src/api/: Use intended license header
[libquvi.git] / src / api / media_get.c
blobdacaa140f4bad139d82938eb2d0ecbc696273c2c
1 /* libquvi
2 * Copyright (C) 2012 Toni Gundogdu <legatvs@gmail.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301 USA
20 /** @file media_get.c */
22 #include "config.h"
24 #include <glib.h>
26 #include "quvi.h"
27 /* -- */
28 #include "_quvi_s.h"
29 #include "_quvi_media_s.h"
31 /* Advances the current stream pointer to the first stream if undefined. */
32 static void _chk_curr_stream(_quvi_media_t qm, _quvi_media_stream_t *qms)
34 if (qm->curr.stream == NULL)
36 const QuviBoolean r = quvi_media_stream_next(qm);
37 g_assert(r == QUVI_TRUE); /* If the stream list is still empty,
38 * quvi_media_get is being used incorrectly.*/
40 g_assert(qm->curr.stream != NULL);
41 *qms = (_quvi_media_stream_t) qm->curr.stream->data;
44 static QuviError _media_get(_quvi_media_t qm, QuviMediaProperty n, ...)
46 _quvi_media_stream_t qms;
47 QuviError rc;
48 gdouble *dp;
49 va_list arg;
50 gchar **sp;
51 glong *lp;
52 gint type;
54 va_start(arg, n);
55 type = QUVI_MEDIA_PROPERTY_TYPE_MASK & (gint) n;
57 dp = NULL;
58 sp = NULL;
59 lp = NULL;
61 rc = QUVI_OK;
62 qms = NULL;
64 switch (type)
66 case QUVI_MEDIA_PROPERTY_TYPE_STRING:
67 sp = va_arg(arg, gchar**);
68 if (sp == NULL)
69 rc = QUVI_ERROR_INVALID_ARG;
70 break;
71 case QUVI_MEDIA_PROPERTY_TYPE_LONG:
72 lp = va_arg(arg, glong*);
73 if (lp == NULL)
74 rc = QUVI_ERROR_INVALID_ARG;
75 break;
76 case QUVI_MEDIA_PROPERTY_TYPE_DOUBLE:
77 dp = va_arg(arg, gdouble*);
78 if (dp == NULL)
79 rc = QUVI_ERROR_INVALID_ARG;
80 break;
81 default:
82 rc = QUVI_ERROR_INVALID_ARG;
83 break;
85 va_end(arg);
87 if (rc != QUVI_OK)
88 return (rc);
90 switch (n)
92 case QUVI_MEDIA_PROPERTY_TITLE:
93 *sp = qm->title->str;
94 break;
95 case QUVI_MEDIA_PROPERTY_ID:
96 *sp = qm->id->str;
97 break;
98 case QUVI_MEDIA_PROPERTY_START_TIME_MS:
99 *dp = qm->start_time_ms;
100 break;
101 case QUVI_MEDIA_PROPERTY_THUMBNAIL_URL:
102 *sp = qm->url.thumbnail->str;
103 break;
104 case QUVI_MEDIA_PROPERTY_DURATION_MS:
105 *dp = qm->duration_ms;
106 break;
109 * Stream properties.
111 * NOTE: These must advance current stream pointer if it is still NULL.
114 case QUVI_MEDIA_STREAM_PROPERTY_VIDEO_ENCODING:
115 _chk_curr_stream(qm, &qms);
116 g_assert(qms != NULL);
117 *sp = qms->video.encoding->str;
118 break;
119 case QUVI_MEDIA_STREAM_PROPERTY_AUDIO_ENCODING:
120 _chk_curr_stream(qm, &qms);
121 g_assert(qms != NULL);
122 *sp = qms->audio.encoding->str;
123 break;
124 case QUVI_MEDIA_STREAM_PROPERTY_CONTAINER:
125 _chk_curr_stream(qm, &qms);
126 g_assert(qms != NULL);
127 *sp = qms->container->str;
128 break;
129 case QUVI_MEDIA_STREAM_PROPERTY_URL:
130 _chk_curr_stream(qm, &qms);
131 g_assert(qms != NULL);
132 *sp = qms->url->str;
133 break;
134 case QUVI_MEDIA_STREAM_PROPERTY_ID:
135 _chk_curr_stream(qm, &qms);
136 g_assert(qms != NULL);
137 *sp = qms->id->str;
138 break;
139 case QUVI_MEDIA_STREAM_PROPERTY_VIDEO_BITRATE_KBIT_S:
140 _chk_curr_stream(qm, &qms);
141 g_assert(qms != NULL);
142 *dp = qms->video.bitrate_kbit_s;
143 break;
144 case QUVI_MEDIA_STREAM_PROPERTY_AUDIO_BITRATE_KBIT_S:
145 _chk_curr_stream(qm, &qms);
146 g_assert(qms != NULL);
147 *dp = qms->audio.bitrate_kbit_s;
148 break;
149 case QUVI_MEDIA_STREAM_PROPERTY_VIDEO_HEIGHT:
150 _chk_curr_stream(qm, &qms);
151 g_assert(qms != NULL);
152 *dp = qms->video.height;
153 break;
154 case QUVI_MEDIA_STREAM_PROPERTY_VIDEO_WIDTH:
155 _chk_curr_stream(qm, &qms);
156 g_assert(qms != NULL);
157 *dp = qms->video.width;
158 break;
160 default:
161 rc = QUVI_ERROR_INVALID_ARG;
162 break;
164 return (rc);
167 /** @brief Return a media property
168 @sa @ref parse_media
169 @ingroup mediaprop
170 @note Using any of the QUVI_MEDIA_STREAM_PROPERTY_* values will cause
171 the library to advance to the first stream in the list, this will
172 conflict with the use of @ref quvi_media_stream_next, causing it to
173 continue from the second stream, not the first one
175 void quvi_media_get(quvi_media_t handle, QuviMediaProperty property, ...)
177 _quvi_media_t qm;
178 va_list arg;
179 gpointer p;
180 _quvi_t q;
182 /* If G_DISABLE_CHECKS is defined then the check is not performed. */
183 g_return_if_fail(handle != NULL);
185 va_start(arg, property);
186 p = va_arg(arg, gpointer);
187 va_end(arg);
189 qm = (_quvi_media_t) handle;
190 q = qm->handle.quvi;
192 q->status.rc = _media_get(qm, property, p);
195 /* vim: set ts=2 sw=2 tw=72 expandtab: */