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
20 /** @file media_get.c */
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
;
55 type
= QUVI_MEDIA_PROPERTY_TYPE_MASK
& (gint
) n
;
66 case QUVI_MEDIA_PROPERTY_TYPE_STRING
:
67 sp
= va_arg(arg
, gchar
**);
69 rc
= QUVI_ERROR_INVALID_ARG
;
71 case QUVI_MEDIA_PROPERTY_TYPE_LONG
:
72 lp
= va_arg(arg
, glong
*);
74 rc
= QUVI_ERROR_INVALID_ARG
;
76 case QUVI_MEDIA_PROPERTY_TYPE_DOUBLE
:
77 dp
= va_arg(arg
, gdouble
*);
79 rc
= QUVI_ERROR_INVALID_ARG
;
82 rc
= QUVI_ERROR_INVALID_ARG
;
92 case QUVI_MEDIA_PROPERTY_TITLE
:
95 case QUVI_MEDIA_PROPERTY_ID
:
98 case QUVI_MEDIA_PROPERTY_START_TIME_MS
:
99 *dp
= qm
->start_time_ms
;
101 case QUVI_MEDIA_PROPERTY_THUMBNAIL_URL
:
102 *sp
= qm
->url
.thumbnail
->str
;
104 case QUVI_MEDIA_PROPERTY_DURATION_MS
:
105 *dp
= qm
->duration_ms
;
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
;
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
;
124 case QUVI_MEDIA_STREAM_PROPERTY_CONTAINER
:
125 _chk_curr_stream(qm
, &qms
);
126 g_assert(qms
!= NULL
);
127 *sp
= qms
->container
->str
;
129 case QUVI_MEDIA_STREAM_PROPERTY_URL
:
130 _chk_curr_stream(qm
, &qms
);
131 g_assert(qms
!= NULL
);
134 case QUVI_MEDIA_STREAM_PROPERTY_ID
:
135 _chk_curr_stream(qm
, &qms
);
136 g_assert(qms
!= NULL
);
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
;
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
;
149 case QUVI_MEDIA_STREAM_PROPERTY_VIDEO_HEIGHT
:
150 _chk_curr_stream(qm
, &qms
);
151 g_assert(qms
!= NULL
);
152 *dp
= qms
->video
.height
;
154 case QUVI_MEDIA_STREAM_PROPERTY_VIDEO_WIDTH
:
155 _chk_curr_stream(qm
, &qms
);
156 g_assert(qms
!= NULL
);
157 *dp
= qms
->video
.width
;
161 rc
= QUVI_ERROR_INVALID_ARG
;
167 /** @brief Return a media property
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
, ...)
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
);
189 qm
= (_quvi_media_t
) handle
;
192 q
->status
.rc
= _media_get(qm
, property
, p
);
195 /* vim: set ts=2 sw=2 tw=72 expandtab: */