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_stream_select.c */
25 #include <glib/gi18n-lib.h>
31 #include "_quvi_media_s.h"
35 static QuviError
_select(_quvi_media_t qm
, const gchar
*id
)
37 _quvi_media_stream_t qms
;
44 quvi_media_stream_reset(qm
);
47 r
= g_strsplit(id
, ",", 0);
51 for (i
=0; (r
[i
] != NULL
&& found_flag
== FALSE
); ++i
)
53 if (g_strcmp0(r
[i
], "croak") ==0)
55 rc
= QUVI_ERROR_KEYWORD_CROAK
;
58 else if (g_strcmp0(r
[i
], "best") == 0)
60 quvi_media_stream_choose_best(qm
);
65 while (quvi_media_stream_next(qm
) == QUVI_TRUE
)
67 /* TODO: Use quvi_media_get? */
68 qms
= (_quvi_media_stream_t
) qm
->curr
.stream
->data
;
70 found_flag
= m_match(qms
->id
->str
, r
[i
]);
71 if (found_flag
== TRUE
)
75 if (found_flag
== FALSE
) /* Use the first stream as a fallback. */
76 quvi_media_stream_reset(qm
);
83 /** @brief Select a @ref m_stream matching a @ref m_stream_id
85 Matches the @ref m_stream_id (pattern) to the available media stream
86 IDs and selects the stream. This function returns immediately
87 if a matching ID was found. The ID value may be a comma-separated value
88 (e.g. "foo,bar,baz"). The ID may also contain the keywords 'croak' and
89 'best' (see the notes below).
91 - ID value is used as regular expression pattern
92 - ID may contain the reserved keyword 'best'
93 - Defining this in the ID is identical to calling
94 @ref quvi_media_stream_choose_best, refer to it for details
95 - ID may contain the reserved keyword 'croak'
96 - This will cause the function to exit immediately when it is reached
97 - The result may be checked with @ref quvi_ok
98 - The code may be retrieved using @ref quvi_get
99 - The error message may be retrieved using @ref quvi_errmsg
100 - If nothing matched (and the 'croak' keyword was specified) the
101 function will return the first (default) available language
102 - Always confirm the result with @ref quvi_ok
106 void quvi_media_stream_select(quvi_media_t handle
, const char *id
)
111 /* If G_DISABLE_CHECKS is defined then the check is not performed. */
112 g_return_if_fail(handle
!= NULL
);
114 qm
= (_quvi_media_t
) handle
;
117 q
->status
.rc
= _select(qm
, id
);
120 /* vim: set ts=2 sw=2 tw=72 expandtab: */