2 * Copyright (C) 2012,2013 Toni Gundogdu <legatvs@gmail.com>
4 * This file is part of libquvi <http://quvi.sourceforge.net/>.
6 * This library is free software: you can redistribute it and/or
7 * modify it under the terms of the GNU Affero General Public
8 * License as published by the Free Software Foundation, either
9 * version 3 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General
17 * Public License along with this library. If not, see
18 * <http://www.gnu.org/licenses/>.
21 /** @file media_get.c */
30 #include "_quvi_media_s.h"
32 /* Advances the current stream pointer to the first stream if undefined. */
33 static void _chk_curr_stream(_quvi_media_t qm
, _quvi_media_stream_t
*qms
)
35 if (qm
->curr
.stream
== NULL
)
37 const QuviBoolean r
= quvi_media_stream_next(qm
);
38 g_assert(r
== QUVI_TRUE
); /* If the stream list is still empty,
39 * quvi_media_get is being used incorrectly.*/
41 g_assert(qm
->curr
.stream
!= NULL
);
42 *qms
= (_quvi_media_stream_t
) qm
->curr
.stream
->data
;
43 g_assert(*qms
!= NULL
);
46 static QuviError
_media_get(_quvi_media_t qm
, const QuviMediaProperty n
, ...)
48 _quvi_media_stream_t qms
;
57 type
= QUVI_MEDIA_PROPERTY_TYPE_MASK
& (gint
) n
;
68 case QUVI_MEDIA_PROPERTY_TYPE_STRING
:
69 sp
= va_arg(arg
, gchar
**);
71 rc
= QUVI_ERROR_INVALID_ARG
;
73 case QUVI_MEDIA_PROPERTY_TYPE_LONG
:
74 lp
= va_arg(arg
, glong
*);
76 rc
= QUVI_ERROR_INVALID_ARG
;
78 case QUVI_MEDIA_PROPERTY_TYPE_DOUBLE
:
79 dp
= va_arg(arg
, gdouble
*);
81 rc
= QUVI_ERROR_INVALID_ARG
;
84 rc
= QUVI_ERROR_INVALID_ARG
;
94 case QUVI_MEDIA_PROPERTY_TITLE
:
97 case QUVI_MEDIA_PROPERTY_ID
:
100 case QUVI_MEDIA_PROPERTY_START_TIME_MS
:
101 *dp
= qm
->start_time_ms
;
103 case QUVI_MEDIA_PROPERTY_THUMBNAIL_URL
:
104 *sp
= qm
->url
.thumbnail
->str
;
106 case QUVI_MEDIA_PROPERTY_DURATION_MS
:
107 *dp
= qm
->duration_ms
;
113 * NOTE: These must advance current stream pointer if it is still NULL.
116 case QUVI_MEDIA_STREAM_PROPERTY_VIDEO_ENCODING
:
117 _chk_curr_stream(qm
, &qms
);
118 *sp
= qms
->video
.encoding
->str
;
120 case QUVI_MEDIA_STREAM_PROPERTY_AUDIO_ENCODING
:
121 _chk_curr_stream(qm
, &qms
);
122 *sp
= qms
->audio
.encoding
->str
;
124 case QUVI_MEDIA_STREAM_PROPERTY_CONTAINER
:
125 _chk_curr_stream(qm
, &qms
);
126 *sp
= qms
->container
->str
;
128 case QUVI_MEDIA_STREAM_PROPERTY_URL
:
129 _chk_curr_stream(qm
, &qms
);
132 case QUVI_MEDIA_STREAM_PROPERTY_ID
:
133 _chk_curr_stream(qm
, &qms
);
136 case QUVI_MEDIA_STREAM_PROPERTY_VIDEO_BITRATE_KBIT_S
:
137 _chk_curr_stream(qm
, &qms
);
138 *dp
= qms
->video
.bitrate_kbit_s
;
140 case QUVI_MEDIA_STREAM_PROPERTY_AUDIO_BITRATE_KBIT_S
:
141 _chk_curr_stream(qm
, &qms
);
142 *dp
= qms
->audio
.bitrate_kbit_s
;
144 case QUVI_MEDIA_STREAM_PROPERTY_VIDEO_HEIGHT
:
145 _chk_curr_stream(qm
, &qms
);
146 *dp
= qms
->video
.height
;
148 case QUVI_MEDIA_STREAM_PROPERTY_VIDEO_WIDTH
:
149 _chk_curr_stream(qm
, &qms
);
150 *dp
= qms
->video
.width
;
154 rc
= QUVI_ERROR_INVALID_ARG
;
160 /** @brief Return a media property
164 - Accessing any of the QUVI_MEDIA_STREAM_PROPERTY_* values using this
165 function will cause the library to advance to the first stream in
166 the list, this will conflict with @ref quvi_media_stream_next,
167 causing @ref quvi_media_stream_next to advance from the second
168 stream, not the first stream
169 - URLs will be returned in the escaped form
171 void quvi_media_get(quvi_media_t handle
, QuviMediaProperty property
, ...)
178 /* If G_DISABLE_CHECKS is defined then the check is not performed. */
179 g_return_if_fail(handle
!= NULL
);
181 va_start(arg
, property
);
182 p
= va_arg(arg
, gpointer
);
185 qm
= (_quvi_media_t
) handle
;
188 q
->status
.rc
= _media_get(qm
, property
, p
);
191 /* vim: set ts=2 sw=2 tw=72 expandtab: */