gst-play: Allow disabling audio/video/subtitle tracks

When cycling through tracks, add 'disable' to the set
of states.
This commit is contained in:
Jan Schmidt 2016-07-15 22:47:02 +10:00
parent 614ddaa739
commit 657a9c23d6

View file

@ -920,6 +920,7 @@ play_cycle_track_selection (GstPlay * play, GstPlayTrackType track_type)
{ {
const gchar *prop_cur, *prop_n, *prop_get, *name; const gchar *prop_cur, *prop_n, *prop_get, *name;
gint cur = -1, n = -1; gint cur = -1, n = -1;
guint flag, cur_flags;
switch (track_type) { switch (track_type) {
case GST_PLAY_TRACK_TYPE_AUDIO: case GST_PLAY_TRACK_TYPE_AUDIO:
@ -927,48 +928,67 @@ play_cycle_track_selection (GstPlay * play, GstPlayTrackType track_type)
prop_cur = "current-audio"; prop_cur = "current-audio";
prop_n = "n-audio"; prop_n = "n-audio";
name = "audio"; name = "audio";
flag = 0x2;
break; break;
case GST_PLAY_TRACK_TYPE_VIDEO: case GST_PLAY_TRACK_TYPE_VIDEO:
prop_get = "get-video-tags"; prop_get = "get-video-tags";
prop_cur = "current-video"; prop_cur = "current-video";
prop_n = "n-video"; prop_n = "n-video";
name = "video"; name = "video";
flag = 0x1;
break; break;
case GST_PLAY_TRACK_TYPE_SUBTITLE: case GST_PLAY_TRACK_TYPE_SUBTITLE:
prop_get = "get-text-tags"; prop_get = "get-text-tags";
prop_cur = "current-text"; prop_cur = "current-text";
prop_n = "n-text"; prop_n = "n-text";
name = "subtitle"; name = "subtitle";
flag = 0x4;
break; break;
default: default:
return; return;
} }
g_object_get (play->playbin, prop_cur, &cur, prop_n, &n, NULL); g_object_get (play->playbin, prop_cur, &cur, prop_n, &n, "flags", &cur_flags,
NULL);
if (n < 1) { if (n < 1) {
g_print ("No %s tracks.\n", name); g_print ("No %s tracks.\n", name);
} else if (n == 1) {
g_print ("No other %s tracks to switch to.\n", name);
} else { } else {
gchar *lcode = NULL, *lname = NULL; gchar *lcode = NULL, *lname = NULL;
const gchar *lang = NULL; const gchar *lang = NULL;
GstTagList *tags = NULL; GstTagList *tags = NULL;
cur = (cur + 1) % n; if (!(cur_flags & flag))
g_signal_emit_by_name (play->playbin, prop_get, cur, &tags); cur = 0;
if (tags != NULL) {
if (gst_tag_list_get_string (tags, GST_TAG_LANGUAGE_CODE, &lcode))
lang = gst_tag_get_language_name (lcode);
else if (gst_tag_list_get_string (tags, GST_TAG_LANGUAGE_NAME, &lname))
lang = lname;
gst_tag_list_unref (tags);
}
if (lang != NULL)
g_print ("Switching to %s track %d of %d (%s).\n", name, cur + 1, n,
lang);
else else
g_print ("Switching to %s track %d of %d.\n", name, cur + 1, n); cur = (cur + 1) % (n + 1);
if (cur >= n) {
cur = -1;
g_print ("Disabling %s. \n", name);
if (cur_flags & flag) {
cur_flags &= ~flag;
g_object_set (play->playbin, "flags", cur_flags, NULL);
}
} else {
if (!(cur_flags & flag)) {
cur_flags |= flag;
g_object_set (play->playbin, "flags", cur_flags, NULL);
}
g_signal_emit_by_name (play->playbin, prop_get, cur, &tags);
if (tags != NULL) {
if (gst_tag_list_get_string (tags, GST_TAG_LANGUAGE_CODE, &lcode))
lang = gst_tag_get_language_name (lcode);
else if (gst_tag_list_get_string (tags, GST_TAG_LANGUAGE_NAME, &lname))
lang = lname;
gst_tag_list_unref (tags);
}
if (lang != NULL)
g_print ("Switching to %s track %d of %d (%s).\n", name, cur + 1, n,
lang);
else
g_print ("Switching to %s track %d of %d.\n", name, cur + 1, n);
}
g_object_set (play->playbin, prop_cur, cur, NULL); g_object_set (play->playbin, prop_cur, cur, NULL);
g_free (lcode); g_free (lcode);
g_free (lname); g_free (lname);