api: quvi_media_stream_select: Revise doxy comment
[libquvi.git] / src / api / media_stream_select.c
blobcc5d19f15ba67fdc1fb2c593a9783845b6950505
1 /* libquvi
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 */
23 #include "config.h"
25 #include <glib/gi18n-lib.h>
26 #include <glib.h>
28 #include "quvi.h"
29 /* -- */
30 #include "_quvi_s.h"
31 #include "_quvi_media_s.h"
32 /* -- */
33 #include "misc/re.h"
35 static QuviError _select(_quvi_media_t qm, const gchar *id)
37 _quvi_media_stream_t qms;
38 gboolean found_flag;
39 QuviError rc;
40 _quvi_t q;
41 gchar **r;
42 gint i;
44 quvi_media_stream_reset(qm);
45 q = qm->handle.quvi;
47 r = g_strsplit(id, ",", 0);
48 found_flag = FALSE;
49 rc = QUVI_OK;
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;
56 break;
58 else if (g_strcmp0(r[i], "best") == 0)
60 quvi_media_stream_choose_best(qm);
61 break;
63 else
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)
72 break;
75 if (found_flag == FALSE) /* Use the first stream as a fallback. */
76 quvi_media_stream_reset(qm);
79 g_strfreev(r);
80 return (rc);
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).
90 @note
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
103 @sa @ref parse_media
104 @ingroup mediaprop
106 void quvi_media_stream_select(quvi_media_t handle, const char *id)
108 _quvi_media_t qm;
109 _quvi_t q;
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;
115 q = qm->handle.quvi;
117 q->status.rc = _select(qm, id);
120 /* vim: set ts=2 sw=2 tw=72 expandtab: */