From 6368102c5e3525af8069b62ecea0e7cdc0d54b67 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Mon, 12 Jan 2004 21:34:08 +0000 Subject: [PATCH] Properly handle the default track flags, even when reading Matroska files. --- ChangeLog | 3 +++ src/input/r_matroska.cpp | 7 +++++-- src/mkvmerge.cpp | 7 +++---- src/mkvmerge.h | 2 +- src/pr_generic.cpp | 39 +++++++++++---------------------------- src/pr_generic.h | 8 ++++++-- 6 files changed, 29 insertions(+), 37 deletions(-) diff --git a/ChangeLog b/ChangeLog index 99293eda2..a21f16b0e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2004-01-12 Moritz Bunkus + * mkvmerge: bug fix: The default track flags could not be + overriden on the command line when reading Matroska files. + * Windows binaries after v0.8.1 require a new runtime DLL archive. Please download it from http://www.bunkus.org/videotools/mkvtoolnix/ Thanks. diff --git a/src/input/r_matroska.cpp b/src/input/r_matroska.cpp index 4b0d741f6..c1603d6d4 100644 --- a/src/input/r_matroska.cpp +++ b/src/input/r_matroska.cpp @@ -82,6 +82,8 @@ using namespace std; using namespace libmatroska; #define PFX "matroska_reader: " +#define MAP_TRACK_TYPE(c) ((c) == 'a' ? track_audio : \ + (c) == 'v' ? track_video : track_subtitle) // }}} @@ -1247,8 +1249,6 @@ void kax_reader_c::create_packetizer(int64_t tid) { nti->private_data = (unsigned char *)safememdup(t->private_data, t->private_size); nti->private_size = t->private_size; - if (nti->default_track == 0) - nti->default_track = t->default_track; if (nti->language == NULL) nti->language = safestrdup(t->language); if (nti->track_name == NULL) @@ -1447,6 +1447,9 @@ void kax_reader_c::create_packetizer(int64_t tid) { mxerror(PFX "Unsupported track type for track %d.\n", t->tnum); break; } + if (t->default_track) + t->packetizer->set_as_default_track(MAP_TRACK_TYPE(t->type), + DEFAULT_TRACK_PRIORITY_FROM_SOURCE); if (t->tuid != 0) if (!t->packetizer->set_uid(t->tuid)) mxwarn(PFX "Could not keep the track UID %u because it is already " diff --git a/src/mkvmerge.cpp b/src/mkvmerge.cpp index f973eacc2..f5423f44e 100644 --- a/src/mkvmerge.cpp +++ b/src/mkvmerge.cpp @@ -152,7 +152,7 @@ bool dump_splitpoints = false; bool use_timeslices = false, use_durations = false; float video_fps = -1.0; -int default_tracks[3]; +int default_tracks[3], default_tracks_priority[3]; bool identifying = false, identify_verbose = false; @@ -1924,9 +1924,8 @@ static void init_globals() { kax_sh_cues = NULL; kax_sh_void = NULL; video_fps = -1.0; - default_tracks[0] = 0; - default_tracks[1] = 0; - default_tracks[2] = 0; + memset(default_tracks, 0, sizeof(default_tracks)); + memset(default_tracks_priority, 0, sizeof(default_tracks_priority)); display_counter = 1; display_reader = NULL; clear_list_of_unique_uint32(); diff --git a/src/mkvmerge.h b/src/mkvmerge.h index 2c95b10ff..63fc09d70 100644 --- a/src/mkvmerge.h +++ b/src/mkvmerge.h @@ -71,7 +71,7 @@ extern int pass, file_num; extern bool fast_mode; extern int max_ms_per_cluster, max_blocks_per_cluster; -extern int default_tracks[3]; +extern int default_tracks[3], default_tracks_priority[3]; extern int64_t split_after; extern int split_max_num_files; extern bool split_by_time; diff --git a/src/pr_generic.cpp b/src/pr_generic.cpp index 21e288c98..805774c52 100644 --- a/src/pr_generic.cpp +++ b/src/pr_generic.cpp @@ -316,9 +316,9 @@ void generic_packetizer_c::set_track_type(int type) { htrack_type = type; if (ti->default_track) - force_default_track(type); + set_as_default_track(type, DEFAULT_TRACK_PRIORITY_CMDLINE); else - set_as_default_track(type); + set_as_default_track(type, DEFAULT_TRACK_PRIORITY_FROM_TYPE); } int generic_packetizer_c::get_track_type() { @@ -472,7 +472,7 @@ void generic_packetizer_c::set_video_aspect_ratio(float ar) { ti->aspect_ratio = ar; } -void generic_packetizer_c::set_as_default_track(int type) { +void generic_packetizer_c::set_as_default_track(int type, int priority) { int idx; idx = 0; @@ -486,30 +486,14 @@ void generic_packetizer_c::set_as_default_track(int type) { die("pr_generic.cpp/generic_packetizer_c::set_as_default_track(): Unknown " "track type %d.", type); - if (default_tracks[idx] == 0) - default_tracks[idx] = -1 * hserialno; -} - -void generic_packetizer_c::force_default_track(int type) { - int idx; - - idx = 0; - if (type == track_audio) - idx = 0; - else if (type == track_video) - idx = 1; - else if (type == track_subtitle) - idx = 2; - else - die("pr_generic.cpp/generic_packetizer_c::force_default_track(): Unknown " - "track type %d.", type); - - if ((default_tracks[idx] > 0) && !identifying) - mxwarn("Another default track for %s tracks has already " - "been set. Not setting the 'default' flag for this track.\n", - idx == 0 ? "audio" : idx == 'v' ? "video" : "subtitle"); - else + if (default_tracks_priority[idx] < priority) { + default_tracks_priority[idx] = priority; default_tracks[idx] = hserialno; + } else if (priority == DEFAULT_TRACK_PRIORITY_CMDLINE) + mxwarn("Another default track for %s tracks has already " + "been set. Not setting the 'default' flag for track %lld of " + "'%s'.\n", idx == 0 ? "audio" : idx == 'v' ? "video" : "subtitle", + ti->id, ti->fname); } void generic_packetizer_c::set_language(const char *language) { @@ -580,8 +564,7 @@ void generic_packetizer_c::set_headers() { else idx = 2; - if ((default_tracks[idx] == hserialno) || - (default_tracks[idx] == -1 * hserialno)) + if (default_tracks[idx] == hserialno) *(static_cast (&GetChild(*track_entry))) = 1; else diff --git a/src/pr_generic.h b/src/pr_generic.h index fe194e722..171e450e4 100644 --- a/src/pr_generic.h +++ b/src/pr_generic.h @@ -56,6 +56,11 @@ enum copy_packet_mode_t { cp_no }; +#define DEFAULT_TRACK_PRIOIRTY_NONE 0 +#define DEFAULT_TRACK_PRIORITY_FROM_TYPE 10 +#define DEFAULT_TRACK_PRIORITY_FROM_SOURCE 50 +#define DEFAULT_TRACK_PRIORITY_CMDLINE 255 + typedef struct { KaxBlockGroup *group; KaxBlock *block; @@ -273,8 +278,7 @@ public: virtual void set_video_display_height(int height); virtual void set_video_aspect_ratio(float ar); - virtual void set_as_default_track(int type); - virtual void force_default_track(int type); + virtual void set_as_default_track(int type, int priority); virtual void set_tag_track_uid();