From cc7a2d3287d4bf08a3e85a4bddc41cdfaf55ace7 Mon Sep 17 00:00:00 2001 From: reimar Date: Sun, 23 May 2010 19:49:28 +0000 Subject: [PATCH 01/55] Add code to wake up cache process when e.g. a seek is needed. Dramatically reduces seeking times with lavf ogg demuxer. Needs a spearate implementation for the thread-based cache implementation. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31198 b3059339-0415-0410-9bf9-f77b7e298cf2 --- stream/cache2.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/stream/cache2.c b/stream/cache2.c index 2e2aadc3fe..98268cf46b 100644 --- a/stream/cache2.c +++ b/stream/cache2.c @@ -90,6 +90,14 @@ static int min_fill=0; int cache_fill_status=0; +static void cache_wakeup(stream_t *s) +{ +#if !defined(__MINGW32__) && !defined(PTHREAD_CACHE) && !defined(__OS2__) + // signal process to wake up immediately + kill(s->cache_pid, SIGUSR1); +#endif +} + static void cache_stats(cache_vars_t *s) { int newb=s->max_filepos-s->read_filepos; // new bytes in the buffer @@ -329,6 +337,9 @@ static void exit_sighandler(int x){ exit(0); } +static void dummy_sighandler(int x) { +} + /** * \return 1 on success, 0 if the function was interrupted and -1 on error */ @@ -420,6 +431,7 @@ static void ThreadProc( void *s ){ #endif // cache thread mainloop: signal(SIGTERM,exit_sighandler); // kill + signal(SIGUSR1, dummy_sighandler); // wakeup do { if(!cache_fill(s)){ usec_sleep(FILL_USLEEP_TIME); // idle @@ -470,6 +482,7 @@ int cache_stream_seek_long(stream_t *stream,off_t pos){ newpos=pos/s->sector_size; newpos*=s->sector_size; // align stream->pos=s->read_filepos=newpos; s->eof=0; // !!!!!!! + cache_wakeup(stream); cache_stream_fill_buffer(stream); @@ -514,6 +527,7 @@ int cache_do_control(stream_t *stream, int cmd, void *arg) { default: return STREAM_UNSUPPORTED; } + cache_wakeup(stream); while (s->control != -1) usec_sleep(CONTROL_SLEEP_TIME); switch (cmd) { From 2ced41082c0bc3135063c2e0ef5ac8ea2837bbc0 Mon Sep 17 00:00:00 2001 From: reimar Date: Sun, 23 May 2010 21:53:48 +0000 Subject: [PATCH 02/55] Optimize cache behaviour for the many-consecutive-seeks case. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31199 b3059339-0415-0410-9bf9-f77b7e298cf2 --- stream/cache2.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/stream/cache2.c b/stream/cache2.c index 98268cf46b..48ebe50123 100644 --- a/stream/cache2.c +++ b/stream/cache2.c @@ -23,6 +23,10 @@ // TODO: seeking, data consistency checking #define READ_USLEEP_TIME 10000 +// These defines are used to reduce the cost of many succesive +// seeks (e.g. when a file has no index) by spinning quickly at first. +#define INITIAL_FILL_USLEEP_TIME 1000 +#define INITIAL_FILL_USLEEP_COUNT 10 #define FILL_USLEEP_TIME 50000 #define PREFILL_SLEEP_TIME 200 #define CONTROL_SLEEP_TIME 0 @@ -432,10 +436,17 @@ static void ThreadProc( void *s ){ // cache thread mainloop: signal(SIGTERM,exit_sighandler); // kill signal(SIGUSR1, dummy_sighandler); // wakeup + { + int sleep_count = 0; do { if(!cache_fill(s)){ + if (sleep_count < INITIAL_FILL_USLEEP_COUNT) { + sleep_count++; + usec_sleep(INITIAL_FILL_USLEEP_TIME); + } else usec_sleep(FILL_USLEEP_TIME); // idle - } + } else + sleep_count = 0; // cache_stats(s->cache_data); } while (cache_execute_control(s)); #if defined(__MINGW32__) || defined(__OS2__) @@ -446,6 +457,7 @@ static void ThreadProc( void *s ){ // make sure forked code never leaves this function exit(0); #endif + } } int cache_stream_fill_buffer(stream_t *s){ From 7dcf9d45ed8b5ac19314f1755fc728d8f6fb3b46 Mon Sep 17 00:00:00 2001 From: diego Date: Sun, 23 May 2010 21:56:22 +0000 Subject: [PATCH 03/55] Remove ambiguous language about indenting if-blocks. The previous version could possibly be misread in a way that forbids reindenting if-blocks. The intended meaning, that whitespace changes should be separated from other changes, is already implied from what is written above that paragraph. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31200 b3059339-0415-0410-9bf9-f77b7e298cf2 --- DOCS/tech/svn-howto.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/DOCS/tech/svn-howto.txt b/DOCS/tech/svn-howto.txt index 40dd4146f0..36a4a6b25c 100644 --- a/DOCS/tech/svn-howto.txt +++ b/DOCS/tech/svn-howto.txt @@ -265,9 +265,6 @@ II. POLICY / RULES: similar) with functional changes in a single commit. Instead, commit such changes as a separate commit of their own. - NOTE: If you had to put if(){ .. } over a large (> 5 lines) chunk of code, - do NOT change the indentation of the inner part (don't move it to the right)! - 7. Always fill out the commit log message. Describe in a few lines what you changed and why. You can refer to mailing list postings if you fix a From 939df8d5a815d72f83a41683611edb738b46e19e Mon Sep 17 00:00:00 2001 From: reimar Date: Sun, 23 May 2010 21:58:50 +0000 Subject: [PATCH 04/55] Extract the cache main loop into a separate function. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31201 b3059339-0415-0410-9bf9-f77b7e298cf2 --- stream/cache2.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/stream/cache2.c b/stream/cache2.c index 48ebe50123..7bdeabd9e3 100644 --- a/stream/cache2.c +++ b/stream/cache2.c @@ -344,6 +344,24 @@ static void exit_sighandler(int x){ static void dummy_sighandler(int x) { } +/** + * Main loop of the cache process or thread. + */ +static void cache_mainloop(cache_vars_t *s) { + int sleep_count = 0; + do { + if (!cache_fill(s)) { + if (sleep_count < INITIAL_FILL_USLEEP_COUNT) { + sleep_count++; + usec_sleep(INITIAL_FILL_USLEEP_TIME); + } else + usec_sleep(FILL_USLEEP_TIME); // idle + } else + sleep_count = 0; +// cache_stats(s->cache_data); + } while (cache_execute_control(s)); +} + /** * \return 1 on success, 0 if the function was interrupted and -1 on error */ @@ -436,19 +454,7 @@ static void ThreadProc( void *s ){ // cache thread mainloop: signal(SIGTERM,exit_sighandler); // kill signal(SIGUSR1, dummy_sighandler); // wakeup - { - int sleep_count = 0; - do { - if(!cache_fill(s)){ - if (sleep_count < INITIAL_FILL_USLEEP_COUNT) { - sleep_count++; - usec_sleep(INITIAL_FILL_USLEEP_TIME); - } else - usec_sleep(FILL_USLEEP_TIME); // idle - } else - sleep_count = 0; -// cache_stats(s->cache_data); - } while (cache_execute_control(s)); + cache_mainloop(s); #if defined(__MINGW32__) || defined(__OS2__) _endthread(); #elif defined(PTHREAD_CACHE) @@ -457,7 +463,6 @@ static void ThreadProc( void *s ){ // make sure forked code never leaves this function exit(0); #endif - } } int cache_stream_fill_buffer(stream_t *s){ From 991b9b9e6d9133daec11f4b3cd39fb81d52fbd9b Mon Sep 17 00:00:00 2001 From: reimar Date: Sun, 23 May 2010 22:04:01 +0000 Subject: [PATCH 05/55] Try reducing the #ifdef mess for the different cache variants. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31202 b3059339-0415-0410-9bf9-f77b7e298cf2 --- stream/cache2.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/stream/cache2.c b/stream/cache2.c index 7bdeabd9e3..e5756e07be 100644 --- a/stream/cache2.c +++ b/stream/cache2.c @@ -439,32 +439,30 @@ err_out: return res; } -#if defined(__MINGW32__) || defined(PTHREAD_CACHE) || defined(__OS2__) -} -#ifdef PTHREAD_CACHE -static void *ThreadProc( void *s ){ -#else -static void ThreadProc( void *s ){ -#endif -#endif - +#if !defined(__MINGW32__) && !defined(PTHREAD_CACHE) && !defined(__OS2__) #ifdef CONFIG_GUI use_gui = 0; // mp_msg may not use gui stuff in forked code #endif -// cache thread mainloop: signal(SIGTERM,exit_sighandler); // kill signal(SIGUSR1, dummy_sighandler); // wakeup cache_mainloop(s); -#if defined(__MINGW32__) || defined(__OS2__) - _endthread(); -#elif defined(PTHREAD_CACHE) - return NULL; -#else // make sure forked code never leaves this function exit(0); #endif } +#ifdef PTHREAD_CACHE +static void *ThreadProc( void *s ){ + cache_mainloop(s); + return NULL; +} +#elif defined(__MINGW32__) || defined(__OS2__) +static void ThreadProc( void *s ){ + cache_mainloop(s); + _endthread(); +} +#endif + int cache_stream_fill_buffer(stream_t *s){ int len; if(s->eof){ s->buf_pos=s->buf_len=0; return 0; } From bc2adc2e4816847bcf4ef33e1f1a1e6fdda115af Mon Sep 17 00:00:00 2001 From: reimar Date: Sun, 23 May 2010 22:09:40 +0000 Subject: [PATCH 06/55] Use an extra define to simplify ifdefs git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31203 b3059339-0415-0410-9bf9-f77b7e298cf2 --- stream/cache2.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/stream/cache2.c b/stream/cache2.c index e5756e07be..9572bda827 100644 --- a/stream/cache2.c +++ b/stream/cache2.c @@ -53,6 +53,10 @@ static void ThreadProc( void *s ); static void *ThreadProc(void *s); #else #include +#define FORKED_CACHE 1 +#endif +#ifndef FORKED_CACHE +#define FORKED_CACHE 0 #endif #include "mp_msg.h" @@ -96,7 +100,7 @@ int cache_fill_status=0; static void cache_wakeup(stream_t *s) { -#if !defined(__MINGW32__) && !defined(PTHREAD_CACHE) && !defined(__OS2__) +#if FORKED_CACHE // signal process to wake up immediately kill(s->cache_pid, SIGUSR1); #endif @@ -277,7 +281,7 @@ static int cache_execute_control(cache_vars_t *s) { static cache_vars_t* cache_init(int size,int sector){ int num; -#if !defined(__MINGW32__) && !defined(PTHREAD_CACHE) && !defined(__OS2__) +#if FORKED_CACHE cache_vars_t* s=shmem_alloc(sizeof(cache_vars_t)); #else cache_vars_t* s=malloc(sizeof(cache_vars_t)); @@ -291,14 +295,14 @@ static cache_vars_t* cache_init(int size,int sector){ }//32kb min_size s->buffer_size=num*sector; s->sector_size=sector; -#if !defined(__MINGW32__) && !defined(PTHREAD_CACHE) && !defined(__OS2__) +#if FORKED_CACHE s->buffer=shmem_alloc(s->buffer_size); #else s->buffer=malloc(s->buffer_size); #endif if(s->buffer == NULL){ -#if !defined(__MINGW32__) && !defined(PTHREAD_CACHE) && !defined(__OS2__) +#if FORKED_CACHE shmem_free(s,sizeof(cache_vars_t)); #else free(s); @@ -314,7 +318,7 @@ static cache_vars_t* cache_init(int size,int sector){ void cache_uninit(stream_t *s) { cache_vars_t* c = s->cache_data; if(s->cache_pid) { -#if defined(__MINGW32__) || defined(PTHREAD_CACHE) || defined(__OS2__) +#if !FORKED_CACHE cache_do_control(s, -2, NULL); #else kill(s->cache_pid,SIGKILL); @@ -323,7 +327,7 @@ void cache_uninit(stream_t *s) { s->cache_pid = 0; } if(!c) return; -#if defined(__MINGW32__) || defined(PTHREAD_CACHE) || defined(__OS2__) +#if !FORKED_CACHE free(c->buffer); c->buffer = NULL; c->stream = NULL; @@ -391,7 +395,7 @@ int stream_enable_cache(stream_t *stream,int size,int min,int seek_limit){ min = s->buffer_size - s->fill_limit; } -#if !defined(__MINGW32__) && !defined(PTHREAD_CACHE) && !defined(__OS2__) +#if FORKED_CACHE if((stream->cache_pid=fork())){ if ((pid_t)stream->cache_pid == -1) stream->cache_pid = 0; @@ -439,7 +443,7 @@ err_out: return res; } -#if !defined(__MINGW32__) && !defined(PTHREAD_CACHE) && !defined(__OS2__) +#if FORKED_CACHE #ifdef CONFIG_GUI use_gui = 0; // mp_msg may not use gui stuff in forked code #endif @@ -451,16 +455,18 @@ err_out: #endif } -#ifdef PTHREAD_CACHE -static void *ThreadProc( void *s ){ - cache_mainloop(s); - return NULL; -} -#elif defined(__MINGW32__) || defined(__OS2__) +#if !FORKED_CACHE +#if defined(__MINGW32__) || defined(__OS2__) static void ThreadProc( void *s ){ cache_mainloop(s); _endthread(); } +#else +static void *ThreadProc( void *s ){ + cache_mainloop(s); + return NULL; +} +#endif #endif int cache_stream_fill_buffer(stream_t *s){ From 8e84b9288cd6e9036e3c151da13a8c654a77a6cf Mon Sep 17 00:00:00 2001 From: reimar Date: Sun, 23 May 2010 22:26:10 +0000 Subject: [PATCH 07/55] Slightly reduce number of #ifs git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31204 b3059339-0415-0410-9bf9-f77b7e298cf2 --- stream/cache2.c | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/stream/cache2.c b/stream/cache2.c index 9572bda827..51989ebd2a 100644 --- a/stream/cache2.c +++ b/stream/cache2.c @@ -279,13 +279,25 @@ static int cache_execute_control(cache_vars_t *s) { return 1; } +static void *shared_alloc(int size) { +#if FORKED_CACHE + return shmem_alloc(size); +#else + return malloc(size); +#endif +} + +static void shared_free(void *ptr, int size) { +#if FORKED_CACHE + shmem_free(ptr, size); +#else + free(ptr); +#endif +} + static cache_vars_t* cache_init(int size,int sector){ int num; -#if FORKED_CACHE - cache_vars_t* s=shmem_alloc(sizeof(cache_vars_t)); -#else - cache_vars_t* s=malloc(sizeof(cache_vars_t)); -#endif + cache_vars_t* s=shared_alloc(sizeof(cache_vars_t)); if(s==NULL) return NULL; memset(s,0,sizeof(cache_vars_t)); @@ -295,18 +307,10 @@ static cache_vars_t* cache_init(int size,int sector){ }//32kb min_size s->buffer_size=num*sector; s->sector_size=sector; -#if FORKED_CACHE - s->buffer=shmem_alloc(s->buffer_size); -#else - s->buffer=malloc(s->buffer_size); -#endif + s->buffer=shared_alloc(s->buffer_size); if(s->buffer == NULL){ -#if FORKED_CACHE - shmem_free(s,sizeof(cache_vars_t)); -#else - free(s); -#endif + shared_free(s, sizeof(cache_vars_t)); return NULL; } @@ -327,16 +331,10 @@ void cache_uninit(stream_t *s) { s->cache_pid = 0; } if(!c) return; -#if !FORKED_CACHE - free(c->buffer); + shared_free(c->buffer, c->buffer_size); c->buffer = NULL; c->stream = NULL; - free(s->cache_data); -#else - shmem_free(c->buffer,c->buffer_size); - c->buffer = NULL; - shmem_free(s->cache_data,sizeof(cache_vars_t)); -#endif + shared_free(s->cache_data, sizeof(cache_vars_t)); s->cache_data = NULL; } From 4ad8b9e0cc6e3c370d682a08e877ffbff992089e Mon Sep 17 00:00:00 2001 From: reimar Date: Sun, 23 May 2010 23:22:25 +0000 Subject: [PATCH 08/55] Use MP_NOPTS_VALUE as "default" pts for delayed frames instead of some insanely large value. Avoids hang if a decoder handles the data/size == 0 condition incorrectly. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31205 b3059339-0415-0410-9bf9-f77b7e298cf2 --- mplayer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mplayer.c b/mplayer.c index 4df25a5010..fdb3b1c90b 100644 --- a/mplayer.c +++ b/mplayer.c @@ -1801,7 +1801,7 @@ static int generate_video_frame(sh_video_t *sh_video, demux_stream_t *d_video) if (in_size < 0) { // try to extract last frames in case of decoder lag in_size = 0; - pts = 1e300; + pts = MP_NOPTS_VALUE; hit_eof = 1; } if (in_size > max_framesize) From 9016e5cf0ab3bd42befb7ceadbb4b3224d5df61b Mon Sep 17 00:00:00 2001 From: reimar Date: Sun, 23 May 2010 23:24:25 +0000 Subject: [PATCH 09/55] Avoid decoding of 0-size packets. This also fixes that the main loop believes tehre is an infinite number of delayed frames, thus never finishing (happens with -demuxer lavf -vc theora). git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31206 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libmpcodecs/vd_theora.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libmpcodecs/vd_theora.c b/libmpcodecs/vd_theora.c index c39e85bf1a..9da6e2d6cd 100644 --- a/libmpcodecs/vd_theora.c +++ b/libmpcodecs/vd_theora.c @@ -168,6 +168,10 @@ static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags) yuv_buffer yuv; mp_image_t* mpi; + // no delayed frames + if (!data || !len) + return NULL; + memset (&op, 0, sizeof (op)); op.bytes = len; op.packet = data; From 3009c1eff42a747959255492a69b9235de271b2c Mon Sep 17 00:00:00 2001 From: reimar Date: Mon, 24 May 2010 17:36:23 +0000 Subject: [PATCH 10/55] Fix OpenGL autodetection to not leave values at -1. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31207 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libvo/vo_gl.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/libvo/vo_gl.c b/libvo/vo_gl.c index 815fa27555..37ccd796de 100644 --- a/libvo/vo_gl.c +++ b/libvo/vo_gl.c @@ -487,12 +487,19 @@ static void autodetectGlExtensions(void) { ati_broken_pbo = ver && ver < 8395; } if (ati_hack == -1) ati_hack = ati_broken_pbo; - if (force_pbo == -1 && extensions && strstr(extensions, "_pixel_buffer_object")) - force_pbo = is_ati; - if (use_rectangle == -1 && extensions && strstr(extensions, "_texture_non_power_of_two")) + if (force_pbo == -1) { + force_pbo = 0; + if (extensions && strstr(extensions, "_pixel_buffer_object")) + force_pbo = is_ati; + } + if (use_rectangle == -1) { use_rectangle = 0; - if (use_rectangle == -1 && extensions && strstr(extensions, "_texture_rectangle")) - use_rectangle = renderer && strstr(renderer, "Mesa DRI R200") ? 1 : 0; + if (extensions) { +// if (strstr(extensions, "_texture_non_power_of_two")) + if (strstr(extensions, "_texture_rectangle")) + use_rectangle = renderer && strstr(renderer, "Mesa DRI R200") ? 1 : 0; + } + } if (use_osd == -1) use_osd = mpglBindTexture != NULL; if (use_yuv == -1) From 25cb4330c92a107537483a26ae3b0cdc92eff532 Mon Sep 17 00:00:00 2001 From: reimar Date: Mon, 24 May 2010 17:51:15 +0000 Subject: [PATCH 11/55] Change -vo md5sum to not interleave U and V lines when calculating the MD5, thus making it match FFmpeg's -f framemd5. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31208 b3059339-0415-0410-9bf9-f77b7e298cf2 --- Changelog | 1 + libvo/vo_md5sum.c | 2 ++ 2 files changed, 3 insertions(+) diff --git a/Changelog b/Changelog index c9a0264d91..b15c7fb655 100644 --- a/Changelog +++ b/Changelog @@ -25,6 +25,7 @@ MPlayer (1.0) * support ISDB-Tb DVB streams Drivers: + * -vo md5sum md5 calculation changed so output matches FFmpeg's -f framemd5 * Support for more formats in OpenGL video output drivers (different YUV subsampling, 16 bit per component) * Selectable YUV to RGB conversion standard for -vo gl diff --git a/libvo/vo_md5sum.c b/libvo/vo_md5sum.c index 2ee3a9e65c..70f2551a1b 100644 --- a/libvo/vo_md5sum.c +++ b/libvo/vo_md5sum.c @@ -219,6 +219,8 @@ static uint32_t draw_image(mp_image_t *mpi) h = h / 2; for (i=0; i Date: Mon, 24 May 2010 19:32:17 +0000 Subject: [PATCH 12/55] make configure use pkg-config for fribidi checks fribidi upstream has dropped fribidi-config in favor of pkg-config now: http://lists.freedesktop.org/archives/fribidi/2008-May/000532.html This commit fixes: http://bugzilla.mplayerhq.hu/show_bug.cgi?id=1675 https://launchpad.net/bugs/556200 http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=582784 git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31209 b3059339-0415-0410-9bf9-f77b7e298cf2 --- configure | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/configure b/configure index 6308d11878..a8519c71a8 100755 --- a/configure +++ b/configure @@ -488,7 +488,6 @@ Use these options if autodetection fails: --with-xvmclib=NAME adapter-specific library name (e.g. XvMCNVIDIA) --with-freetype-config=PATH path to freetype-config - --with-fribidi-config=PATH path to fribidi-config --with-glib-config=PATH path to glib*-config --with-gtk-config=PATH path to gtk*-config --with-sdl-config=PATH path to sdl*-config @@ -740,7 +739,6 @@ _macosx_bundle=auto _sortsub=yes _freetypeconfig='freetype-config' _fribidi=auto -_fribidiconfig='fribidi-config' _enca=auto _inet6=auto _gethostbyname2=auto @@ -800,9 +798,6 @@ for ac_option do --with-freetype-config=*) _freetypeconfig=$(echo $ac_option | cut -d '=' -f 2) ;; - --with-fribidi-config=*) - _fribidiconfig=$(echo $ac_option | cut -d '=' -f 2) - ;; --with-gtk-config=*) _gtkconfig=$(echo $ac_option | cut -d '=' -f 2) ;; @@ -6458,15 +6453,9 @@ int main(void) { } EOF _fribidi=no - _inc_tmp="" - _ld_tmp="-lfribidi" + _inc_tmp="$($_pkg_config --cflags fribidi)" + _ld_tmp="$($_pkg_config --libs fribidi)" cc_check $_inc_tmp $_ld_tmp && _fribidi=yes - if $_fribidiconfig --version > /dev/null 2>&1 && - test "$_fribidi" = no ; then - _inc_tmp="$($_fribidiconfig --cflags)" - _ld_tmp="$($_fribidiconfig --libs)" - cc_check $_inc_tmp $_ld_tmp && _fribidi=yes - fi fi if test "$_fribidi" = yes ; then def_fribidi='#define CONFIG_FRIBIDI 1' From 2032889bb5a1d3aa35f9b1b1f39771e14e83fbad Mon Sep 17 00:00:00 2001 From: siretart Date: Mon, 24 May 2010 21:13:22 +0000 Subject: [PATCH 13/55] support linking to fribidi without pkg-config reintroduce the logic that was removed with the previous commit. In case the naive approach to link fails, try again with pkg-config. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31210 b3059339-0415-0410-9bf9-f77b7e298cf2 --- configure | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/configure b/configure index a8519c71a8..021708e83d 100755 --- a/configure +++ b/configure @@ -6453,9 +6453,15 @@ int main(void) { } EOF _fribidi=no - _inc_tmp="$($_pkg_config --cflags fribidi)" - _ld_tmp="$($_pkg_config --libs fribidi)" + _inc_tmp="" + _ld_tmp="-lfribidi" cc_check $_inc_tmp $_ld_tmp && _fribidi=yes + if $_pkg_config --exists fribidi > /dev/null 2>&1 && + test "$_fribidi" = no ; then + _inc_tmp="$($_pkg_config --cflags)" + _ld_tmp="$($_pkg_config --libs)" + cc_check $_inc_tmp $_ld_tmp && _fribidi=yes + fi fi if test "$_fribidi" = yes ; then def_fribidi='#define CONFIG_FRIBIDI 1' From d852b590a2aefad3c2050cf2741b4c51af8735ca Mon Sep 17 00:00:00 2001 From: cehoyos Date: Tue, 25 May 2010 10:32:09 +0000 Subject: [PATCH 14/55] Samsung uses SIPP as FourCC for MPEG-4 ASP. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31211 b3059339-0415-0410-9bf9-f77b7e298cf2 --- etc/codecs.conf | 1 + 1 file changed, 1 insertion(+) diff --git a/etc/codecs.conf b/etc/codecs.conf index 21a9cc4855..3b1e356662 100644 --- a/etc/codecs.conf +++ b/etc/codecs.conf @@ -1004,6 +1004,7 @@ videocodec ffodivx fourcc M4T3,DMK2,DIGI,INMC fourcc EPHV,SN40 fourcc uldx,ULDX,VSPX + fourcc SIPP ; Samsung SHR-6040 driver ffmpeg dll mpeg4 ;opendivx out YV12,I420,IYUV From 5267edb92aa269bcaee460ebfcb0e2b7374c3fe5 Mon Sep 17 00:00:00 2001 From: diego Date: Tue, 25 May 2010 11:32:32 +0000 Subject: [PATCH 15/55] Remove unused forward declarations. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31212 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libao2/ao_mpegpes.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/libao2/ao_mpegpes.c b/libao2/ao_mpegpes.c index 7b2d3a5788..27b2d79292 100644 --- a/libao2/ao_mpegpes.c +++ b/libao2/ao_mpegpes.c @@ -293,8 +293,6 @@ static void audio_resume(void) { } -void send_pes_packet(unsigned char* data,int len,int id,int timestamp); -void send_lpcm_packet(unsigned char* data,int len,int id,int timestamp,int freq_id); extern int vo_pts; // return: how many bytes can be played without blocking From db711e4d9c06858b6e6aa492f9ce3cdcb86fe647 Mon Sep 17 00:00:00 2001 From: diego Date: Tue, 25 May 2010 11:34:38 +0000 Subject: [PATCH 16/55] K&R cosmetics: Fix '*' placement. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31213 b3059339-0415-0410-9bf9-f77b7e298cf2 --- command.c | 246 +++++++++++++++++++++++++++--------------------------- 1 file changed, 123 insertions(+), 123 deletions(-) diff --git a/command.c b/command.c index 3a7b0249a3..54e41ff73a 100644 --- a/command.c +++ b/command.c @@ -98,7 +98,7 @@ static void rescale_input_coordinates(int ix, int iy, double *dx, double *dy) vo_dheight, vo_fs); } -static int sub_source_by_pos(MPContext * mpctx, int pos) +static int sub_source_by_pos(MPContext *mpctx, int pos) { int source = -1; int top = -1; @@ -113,7 +113,7 @@ static int sub_source_by_pos(MPContext * mpctx, int pos) return source; } -static int sub_source(MPContext * mpctx) +static int sub_source(MPContext *mpctx) { return sub_source_by_pos(mpctx, mpctx->global_sub_pos); } @@ -168,15 +168,15 @@ static void log_sub(void) ///@{ /// OSD level (RW) -static int mp_property_osdlevel(m_option_t * prop, int action, void *arg, - MPContext * mpctx) +static int mp_property_osdlevel(m_option_t *prop, int action, void *arg, + MPContext *mpctx) { return m_property_choice(prop, action, arg, &osd_level); } /// Loop (RW) -static int mp_property_loop(m_option_t * prop, int action, void *arg, - MPContext * mpctx) +static int mp_property_loop(m_option_t *prop, int action, void *arg, + MPContext *mpctx) { switch (action) { case M_PROPERTY_PRINT: @@ -193,8 +193,8 @@ static int mp_property_loop(m_option_t * prop, int action, void *arg, } /// Playback speed (RW) -static int mp_property_playback_speed(m_option_t * prop, int action, - void *arg, MPContext * mpctx) +static int mp_property_playback_speed(m_option_t *prop, int action, + void *arg, MPContext *mpctx) { switch (action) { case M_PROPERTY_SET: @@ -216,15 +216,15 @@ static int mp_property_playback_speed(m_option_t * prop, int action, } /// filename with path (RO) -static int mp_property_path(m_option_t * prop, int action, void *arg, - MPContext * mpctx) +static int mp_property_path(m_option_t *prop, int action, void *arg, + MPContext *mpctx) { return m_property_string_ro(prop, action, arg, filename); } /// filename without path (RO) -static int mp_property_filename(m_option_t * prop, int action, void *arg, - MPContext * mpctx) +static int mp_property_filename(m_option_t *prop, int action, void *arg, + MPContext *mpctx) { char *f; if (!filename) @@ -237,8 +237,8 @@ static int mp_property_filename(m_option_t * prop, int action, void *arg, } /// Demuxer name (RO) -static int mp_property_demuxer(m_option_t * prop, int action, void *arg, - MPContext * mpctx) +static int mp_property_demuxer(m_option_t *prop, int action, void *arg, + MPContext *mpctx) { if (!mpctx->demuxer) return M_PROPERTY_UNAVAILABLE; @@ -247,8 +247,8 @@ static int mp_property_demuxer(m_option_t * prop, int action, void *arg, } /// Position in the stream (RW) -static int mp_property_stream_pos(m_option_t * prop, int action, void *arg, - MPContext * mpctx) +static int mp_property_stream_pos(m_option_t *prop, int action, void *arg, + MPContext *mpctx) { if (!mpctx->demuxer || !mpctx->demuxer->stream) return M_PROPERTY_UNAVAILABLE; @@ -267,8 +267,8 @@ static int mp_property_stream_pos(m_option_t * prop, int action, void *arg, } /// Stream start offset (RO) -static int mp_property_stream_start(m_option_t * prop, int action, - void *arg, MPContext * mpctx) +static int mp_property_stream_start(m_option_t *prop, int action, + void *arg, MPContext *mpctx) { if (!mpctx->demuxer || !mpctx->demuxer->stream) return M_PROPERTY_UNAVAILABLE; @@ -281,8 +281,8 @@ static int mp_property_stream_start(m_option_t * prop, int action, } /// Stream end offset (RO) -static int mp_property_stream_end(m_option_t * prop, int action, void *arg, - MPContext * mpctx) +static int mp_property_stream_end(m_option_t *prop, int action, void *arg, + MPContext *mpctx) { if (!mpctx->demuxer || !mpctx->demuxer->stream) return M_PROPERTY_UNAVAILABLE; @@ -295,8 +295,8 @@ static int mp_property_stream_end(m_option_t * prop, int action, void *arg, } /// Stream length (RO) -static int mp_property_stream_length(m_option_t * prop, int action, - void *arg, MPContext * mpctx) +static int mp_property_stream_length(m_option_t *prop, int action, + void *arg, MPContext *mpctx) { if (!mpctx->demuxer || !mpctx->demuxer->stream) return M_PROPERTY_UNAVAILABLE; @@ -310,8 +310,8 @@ static int mp_property_stream_length(m_option_t * prop, int action, } /// Media length in seconds (RO) -static int mp_property_length(m_option_t * prop, int action, void *arg, - MPContext * mpctx) +static int mp_property_length(m_option_t *prop, int action, void *arg, + MPContext *mpctx) { double len; @@ -323,8 +323,8 @@ static int mp_property_length(m_option_t * prop, int action, void *arg, } /// Current position in percent (RW) -static int mp_property_percent_pos(m_option_t * prop, int action, - void *arg, MPContext * mpctx) { +static int mp_property_percent_pos(m_option_t *prop, int action, + void *arg, MPContext *mpctx) { int pos; if (!mpctx->demuxer) @@ -354,8 +354,8 @@ static int mp_property_percent_pos(m_option_t * prop, int action, } /// Current position in seconds (RW) -static int mp_property_time_pos(m_option_t * prop, int action, - void *arg, MPContext * mpctx) { +static int mp_property_time_pos(m_option_t *prop, int action, + void *arg, MPContext *mpctx) { if (!(mpctx->sh_video || (mpctx->sh_audio && mpctx->audio_out))) return M_PROPERTY_UNAVAILABLE; @@ -525,8 +525,8 @@ static int mp_property_angle(m_option_t *prop, int action, void *arg, } /// Demuxer meta data -static int mp_property_metadata(m_option_t * prop, int action, void *arg, - MPContext * mpctx) { +static int mp_property_metadata(m_option_t *prop, int action, void *arg, + MPContext *mpctx) { m_property_action_t* ka; char* meta; static m_option_t key_type = @@ -558,8 +558,8 @@ static int mp_property_metadata(m_option_t * prop, int action, void *arg, return M_PROPERTY_NOT_IMPLEMENTED; } -static int mp_property_pause(m_option_t * prop, int action, void *arg, - MPContext * mpctx) +static int mp_property_pause(m_option_t *prop, int action, void *arg, + MPContext *mpctx) { return m_property_flag_ro(prop, action, arg, mpctx->osd_function == OSD_PAUSE); } @@ -572,8 +572,8 @@ static int mp_property_pause(m_option_t * prop, int action, void *arg, ///@{ /// Volume (RW) -static int mp_property_volume(m_option_t * prop, int action, void *arg, - MPContext * mpctx) +static int mp_property_volume(m_option_t *prop, int action, void *arg, + MPContext *mpctx) { if (!mpctx->sh_audio) @@ -628,8 +628,8 @@ static int mp_property_volume(m_option_t * prop, int action, void *arg, } /// Mute (RW) -static int mp_property_mute(m_option_t * prop, int action, void *arg, - MPContext * mpctx) +static int mp_property_mute(m_option_t *prop, int action, void *arg, + MPContext *mpctx) { if (!mpctx->sh_audio) @@ -666,8 +666,8 @@ static int mp_property_mute(m_option_t * prop, int action, void *arg, } /// Audio delay (RW) -static int mp_property_audio_delay(m_option_t * prop, int action, - void *arg, MPContext * mpctx) +static int mp_property_audio_delay(m_option_t *prop, int action, + void *arg, MPContext *mpctx) { if (!(mpctx->sh_audio && mpctx->sh_video)) return M_PROPERTY_UNAVAILABLE; @@ -690,8 +690,8 @@ static int mp_property_audio_delay(m_option_t * prop, int action, } /// Audio codec tag (RO) -static int mp_property_audio_format(m_option_t * prop, int action, - void *arg, MPContext * mpctx) +static int mp_property_audio_format(m_option_t *prop, int action, + void *arg, MPContext *mpctx) { if (!mpctx->sh_audio) return M_PROPERTY_UNAVAILABLE; @@ -699,8 +699,8 @@ static int mp_property_audio_format(m_option_t * prop, int action, } /// Audio codec name (RO) -static int mp_property_audio_codec(m_option_t * prop, int action, - void *arg, MPContext * mpctx) +static int mp_property_audio_codec(m_option_t *prop, int action, + void *arg, MPContext *mpctx) { if (!mpctx->sh_audio || !mpctx->sh_audio->codec) return M_PROPERTY_UNAVAILABLE; @@ -708,8 +708,8 @@ static int mp_property_audio_codec(m_option_t * prop, int action, } /// Audio bitrate (RO) -static int mp_property_audio_bitrate(m_option_t * prop, int action, - void *arg, MPContext * mpctx) +static int mp_property_audio_bitrate(m_option_t *prop, int action, + void *arg, MPContext *mpctx) { if (!mpctx->sh_audio) return M_PROPERTY_UNAVAILABLE; @@ -717,8 +717,8 @@ static int mp_property_audio_bitrate(m_option_t * prop, int action, } /// Samplerate (RO) -static int mp_property_samplerate(m_option_t * prop, int action, void *arg, - MPContext * mpctx) +static int mp_property_samplerate(m_option_t *prop, int action, void *arg, + MPContext *mpctx) { if (!mpctx->sh_audio) return M_PROPERTY_UNAVAILABLE; @@ -733,8 +733,8 @@ static int mp_property_samplerate(m_option_t * prop, int action, void *arg, } /// Number of channels (RO) -static int mp_property_channels(m_option_t * prop, int action, void *arg, - MPContext * mpctx) +static int mp_property_channels(m_option_t *prop, int action, void *arg, + MPContext *mpctx) { if (!mpctx->sh_audio) return M_PROPERTY_UNAVAILABLE; @@ -759,8 +759,8 @@ static int mp_property_channels(m_option_t * prop, int action, void *arg, } /// Balance (RW) -static int mp_property_balance(m_option_t * prop, int action, void *arg, - MPContext * mpctx) +static int mp_property_balance(m_option_t *prop, int action, void *arg, + MPContext *mpctx) { float bal; @@ -810,8 +810,8 @@ static int mp_property_balance(m_option_t * prop, int action, void *arg, } /// Selected audio id (RW) -static int mp_property_audio(m_option_t * prop, int action, void *arg, - MPContext * mpctx) +static int mp_property_audio(m_option_t *prop, int action, void *arg, + MPContext *mpctx) { int current_id, tmp; if (!mpctx->demuxer || !mpctx->demuxer->audio) @@ -884,8 +884,8 @@ static int mp_property_audio(m_option_t * prop, int action, void *arg, } /// Selected video id (RW) -static int mp_property_video(m_option_t * prop, int action, void *arg, - MPContext * mpctx) +static int mp_property_video(m_option_t *prop, int action, void *arg, + MPContext *mpctx) { int current_id, tmp; if (!mpctx->demuxer || !mpctx->demuxer->video) @@ -940,8 +940,8 @@ static int mp_property_video(m_option_t * prop, int action, void *arg, } } -static int mp_property_program(m_option_t * prop, int action, void *arg, - MPContext * mpctx) +static int mp_property_program(m_option_t *prop, int action, void *arg, + MPContext *mpctx) { demux_program_t prog; @@ -977,8 +977,8 @@ static int mp_property_program(m_option_t * prop, int action, void *arg, ///@{ /// Fullscreen state (RW) -static int mp_property_fullscreen(m_option_t * prop, int action, void *arg, - MPContext * mpctx) +static int mp_property_fullscreen(m_option_t *prop, int action, void *arg, + MPContext *mpctx) { if (!mpctx->video_out) @@ -1006,8 +1006,8 @@ static int mp_property_fullscreen(m_option_t * prop, int action, void *arg, } } -static int mp_property_deinterlace(m_option_t * prop, int action, - void *arg, MPContext * mpctx) +static int mp_property_deinterlace(m_option_t *prop, int action, + void *arg, MPContext *mpctx) { int deinterlace; vf_instance_t *vf; @@ -1039,8 +1039,8 @@ static int mp_property_deinterlace(m_option_t * prop, int action, } /// Panscan (RW) -static int mp_property_panscan(m_option_t * prop, int action, void *arg, - MPContext * mpctx) +static int mp_property_panscan(m_option_t *prop, int action, void *arg, + MPContext *mpctx) { if (!mpctx->video_out @@ -1073,8 +1073,8 @@ static int mp_property_panscan(m_option_t * prop, int action, void *arg, /// Helper to set vo flags. /** \ingroup PropertyImplHelper */ -static int mp_property_vo_flag(m_option_t * prop, int action, void *arg, - int vo_ctrl, int *vo_var, MPContext * mpctx) +static int mp_property_vo_flag(m_option_t *prop, int action, void *arg, + int vo_ctrl, int *vo_var, MPContext *mpctx) { if (!mpctx->video_out) @@ -1098,32 +1098,32 @@ static int mp_property_vo_flag(m_option_t * prop, int action, void *arg, } /// Window always on top (RW) -static int mp_property_ontop(m_option_t * prop, int action, void *arg, - MPContext * mpctx) +static int mp_property_ontop(m_option_t *prop, int action, void *arg, + MPContext *mpctx) { return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP, &vo_ontop, mpctx); } /// Display in the root window (RW) -static int mp_property_rootwin(m_option_t * prop, int action, void *arg, - MPContext * mpctx) +static int mp_property_rootwin(m_option_t *prop, int action, void *arg, + MPContext *mpctx) { return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN, &vo_rootwin, mpctx); } /// Show window borders (RW) -static int mp_property_border(m_option_t * prop, int action, void *arg, - MPContext * mpctx) +static int mp_property_border(m_option_t *prop, int action, void *arg, + MPContext *mpctx) { return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER, &vo_border, mpctx); } /// Framedropping state (RW) -static int mp_property_framedropping(m_option_t * prop, int action, - void *arg, MPContext * mpctx) +static int mp_property_framedropping(m_option_t *prop, int action, + void *arg, MPContext *mpctx) { if (!mpctx->sh_video) @@ -1143,8 +1143,8 @@ static int mp_property_framedropping(m_option_t * prop, int action, } /// Color settings, try to use vf/vo then fall back on TV. (RW) -static int mp_property_gamma(m_option_t * prop, int action, void *arg, - MPContext * mpctx) +static int mp_property_gamma(m_option_t *prop, int action, void *arg, + MPContext *mpctx) { int *gamma = prop->priv, r, val; @@ -1200,15 +1200,15 @@ static int mp_property_gamma(m_option_t * prop, int action, void *arg, } /// VSync (RW) -static int mp_property_vsync(m_option_t * prop, int action, void *arg, - MPContext * mpctx) +static int mp_property_vsync(m_option_t *prop, int action, void *arg, + MPContext *mpctx) { return m_property_flag(prop, action, arg, &vo_vsync); } /// Video codec tag (RO) -static int mp_property_video_format(m_option_t * prop, int action, - void *arg, MPContext * mpctx) +static int mp_property_video_format(m_option_t *prop, int action, + void *arg, MPContext *mpctx) { char* meta; if (!mpctx->sh_video) @@ -1242,8 +1242,8 @@ static int mp_property_video_format(m_option_t * prop, int action, } /// Video codec name (RO) -static int mp_property_video_codec(m_option_t * prop, int action, - void *arg, MPContext * mpctx) +static int mp_property_video_codec(m_option_t *prop, int action, + void *arg, MPContext *mpctx) { if (!mpctx->sh_video || !mpctx->sh_video->codec) return M_PROPERTY_UNAVAILABLE; @@ -1252,8 +1252,8 @@ static int mp_property_video_codec(m_option_t * prop, int action, /// Video bitrate (RO) -static int mp_property_video_bitrate(m_option_t * prop, int action, - void *arg, MPContext * mpctx) +static int mp_property_video_bitrate(m_option_t *prop, int action, + void *arg, MPContext *mpctx) { if (!mpctx->sh_video) return M_PROPERTY_UNAVAILABLE; @@ -1261,8 +1261,8 @@ static int mp_property_video_bitrate(m_option_t * prop, int action, } /// Video display width (RO) -static int mp_property_width(m_option_t * prop, int action, void *arg, - MPContext * mpctx) +static int mp_property_width(m_option_t *prop, int action, void *arg, + MPContext *mpctx) { if (!mpctx->sh_video) return M_PROPERTY_UNAVAILABLE; @@ -1270,8 +1270,8 @@ static int mp_property_width(m_option_t * prop, int action, void *arg, } /// Video display height (RO) -static int mp_property_height(m_option_t * prop, int action, void *arg, - MPContext * mpctx) +static int mp_property_height(m_option_t *prop, int action, void *arg, + MPContext *mpctx) { if (!mpctx->sh_video) return M_PROPERTY_UNAVAILABLE; @@ -1279,8 +1279,8 @@ static int mp_property_height(m_option_t * prop, int action, void *arg, } /// Video fps (RO) -static int mp_property_fps(m_option_t * prop, int action, void *arg, - MPContext * mpctx) +static int mp_property_fps(m_option_t *prop, int action, void *arg, + MPContext *mpctx) { if (!mpctx->sh_video) return M_PROPERTY_UNAVAILABLE; @@ -1288,8 +1288,8 @@ static int mp_property_fps(m_option_t * prop, int action, void *arg, } /// Video aspect (RO) -static int mp_property_aspect(m_option_t * prop, int action, void *arg, - MPContext * mpctx) +static int mp_property_aspect(m_option_t *prop, int action, void *arg, + MPContext *mpctx) { if (!mpctx->sh_video) return M_PROPERTY_UNAVAILABLE; @@ -1303,8 +1303,8 @@ static int mp_property_aspect(m_option_t * prop, int action, void *arg, ///@{ /// Text subtitle position (RW) -static int mp_property_sub_pos(m_option_t * prop, int action, void *arg, - MPContext * mpctx) +static int mp_property_sub_pos(m_option_t *prop, int action, void *arg, + MPContext *mpctx) { switch (action) { case M_PROPERTY_SET: @@ -1319,8 +1319,8 @@ static int mp_property_sub_pos(m_option_t * prop, int action, void *arg, } /// Selected subtitles (RW) -static int mp_property_sub(m_option_t * prop, int action, void *arg, - MPContext * mpctx) +static int mp_property_sub(m_option_t *prop, int action, void *arg, + MPContext *mpctx) { demux_stream_t *const d_sub = mpctx->d_sub; const int global_sub_size = mpctx->global_sub_size; @@ -1522,8 +1522,8 @@ static int mp_property_sub(m_option_t * prop, int action, void *arg, } /// Selected sub source (RW) -static int mp_property_sub_source(m_option_t * prop, int action, void *arg, - MPContext * mpctx) +static int mp_property_sub_source(m_option_t *prop, int action, void *arg, + MPContext *mpctx) { int source; if (!mpctx->sh_video || mpctx->global_sub_size <= 0) @@ -1600,8 +1600,8 @@ static int mp_property_sub_source(m_option_t * prop, int action, void *arg, } /// Selected subtitles from specific source (RW) -static int mp_property_sub_by_type(m_option_t * prop, int action, void *arg, - MPContext * mpctx) +static int mp_property_sub_by_type(m_option_t *prop, int action, void *arg, + MPContext *mpctx) { int source, is_cur_source, offset; if (!mpctx->sh_video || mpctx->global_sub_size <= 0) @@ -1700,8 +1700,8 @@ static int mp_property_sub_by_type(m_option_t * prop, int action, void *arg, } /// Subtitle delay (RW) -static int mp_property_sub_delay(m_option_t * prop, int action, void *arg, - MPContext * mpctx) +static int mp_property_sub_delay(m_option_t *prop, int action, void *arg, + MPContext *mpctx) { if (!mpctx->sh_video) return M_PROPERTY_UNAVAILABLE; @@ -1709,8 +1709,8 @@ static int mp_property_sub_delay(m_option_t * prop, int action, void *arg, } /// Alignment of text subtitles (RW) -static int mp_property_sub_alignment(m_option_t * prop, int action, - void *arg, MPContext * mpctx) +static int mp_property_sub_alignment(m_option_t *prop, int action, + void *arg, MPContext *mpctx) { char *name[] = { MSGTR_Top, MSGTR_Center, MSGTR_Bottom }; @@ -1737,8 +1737,8 @@ static int mp_property_sub_alignment(m_option_t * prop, int action, } /// Subtitle visibility (RW) -static int mp_property_sub_visibility(m_option_t * prop, int action, - void *arg, MPContext * mpctx) +static int mp_property_sub_visibility(m_option_t *prop, int action, + void *arg, MPContext *mpctx) { if (!mpctx->sh_video) return M_PROPERTY_UNAVAILABLE; @@ -1759,8 +1759,8 @@ static int mp_property_sub_visibility(m_option_t * prop, int action, #ifdef CONFIG_ASS /// Use margins for libass subtitles (RW) -static int mp_property_ass_use_margins(m_option_t * prop, int action, - void *arg, MPContext * mpctx) +static int mp_property_ass_use_margins(m_option_t *prop, int action, + void *arg, MPContext *mpctx) { if (!mpctx->sh_video) return M_PROPERTY_UNAVAILABLE; @@ -1779,8 +1779,8 @@ static int mp_property_ass_use_margins(m_option_t * prop, int action, #endif /// Show only forced subtitles (RW) -static int mp_property_sub_forced_only(m_option_t * prop, int action, - void *arg, MPContext * mpctx) +static int mp_property_sub_forced_only(m_option_t *prop, int action, + void *arg, MPContext *mpctx) { if (!vo_spudec) return M_PROPERTY_UNAVAILABLE; @@ -1802,8 +1802,8 @@ static int mp_property_sub_forced_only(m_option_t * prop, int action, #ifdef CONFIG_FREETYPE /// Subtitle scale (RW) -static int mp_property_sub_scale(m_option_t * prop, int action, void *arg, - MPContext * mpctx) +static int mp_property_sub_scale(m_option_t *prop, int action, void *arg, + MPContext *mpctx) { switch (action) { @@ -1855,8 +1855,8 @@ static int mp_property_sub_scale(m_option_t * prop, int action, void *arg, #ifdef CONFIG_TV /// TV color settings (RW) -static int mp_property_tv_color(m_option_t * prop, int action, void *arg, - MPContext * mpctx) +static int mp_property_tv_color(m_option_t *prop, int action, void *arg, + MPContext *mpctx) { int r, val; tvi_handle_t *tvh = mpctx->demuxer->priv; @@ -1888,8 +1888,8 @@ static int mp_property_tv_color(m_option_t * prop, int action, void *arg, #endif -static int mp_property_teletext_common(m_option_t * prop, int action, void *arg, - MPContext * mpctx) +static int mp_property_teletext_common(m_option_t *prop, int action, void *arg, + MPContext *mpctx) { int val,result; int base_ioctl=(int)prop->priv; @@ -1928,8 +1928,8 @@ static int mp_property_teletext_common(m_option_t * prop, int action, void *arg, return result == VBI_CONTROL_TRUE ? M_PROPERTY_OK : M_PROPERTY_ERROR; } -static int mp_property_teletext_mode(m_option_t * prop, int action, void *arg, - MPContext * mpctx) +static int mp_property_teletext_mode(m_option_t *prop, int action, void *arg, + MPContext *mpctx) { int result; int val; @@ -1947,8 +1947,8 @@ static int mp_property_teletext_mode(m_option_t * prop, int action, void *arg, return M_PROPERTY_OK; } -static int mp_property_teletext_page(m_option_t * prop, int action, void *arg, - MPContext * mpctx) +static int mp_property_teletext_page(m_option_t *prop, int action, void *arg, + MPContext *mpctx) { int result; int val; @@ -2147,7 +2147,7 @@ char* mp_property_print(const char *name, void* ctx) return ret; } -char *property_expand_string(MPContext * mpctx, char *str) +char *property_expand_string(MPContext *mpctx, char *str) { return m_properties_expand_string(mp_properties, str, mpctx); } @@ -2247,10 +2247,10 @@ static struct { /// Handle commands that set a property. -static int set_property_command(MPContext * mpctx, mp_cmd_t * cmd) +static int set_property_command(MPContext *mpctx, mp_cmd_t *cmd) { int i, r; - m_option_t* prop; + m_option_t *prop; const char *pname; // look for the command @@ -2407,7 +2407,7 @@ static void remove_subtitle_range(MPContext *mpctx, int start, int count) } } -int run_command(MPContext * mpctx, mp_cmd_t * cmd) +int run_command(MPContext *mpctx, mp_cmd_t *cmd) { sh_audio_t * const sh_audio = mpctx->sh_audio; sh_video_t * const sh_video = mpctx->sh_video; @@ -2461,7 +2461,7 @@ int run_command(MPContext * mpctx, mp_cmd_t * cmd) double d; off_t o; if (cmd->args[1].v.f) { - m_option_t* prop; + m_option_t *prop; if((r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_GET_TYPE, &prop, mpctx)) <= 0) From 9bdd03ff3728f57faf13a246d50165a706f84db1 Mon Sep 17 00:00:00 2001 From: diego Date: Tue, 25 May 2010 11:35:56 +0000 Subject: [PATCH 17/55] Remove some commented-out duplicate option entries. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31214 b3059339-0415-0410-9bf9-f77b7e298cf2 --- cfg-common-opts.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/cfg-common-opts.h b/cfg-common-opts.h index e4e555c893..7c67ba0379 100644 --- a/cfg-common-opts.h +++ b/cfg-common-opts.h @@ -239,12 +239,8 @@ {"vop", "-vop has been removed, use -vf instead.\n", CONF_TYPE_PRINT, CONF_NOCFG ,0,0, NULL}, {"vf*", &vf_settings, CONF_TYPE_OBJ_SETTINGS_LIST, 0, 0, 0, &vf_obj_list}, // select audio/video codec (by name) or codec family (by number): -// {"afm", &audio_family, CONF_TYPE_INT, CONF_MIN, 0, 22, NULL}, // keep ranges in sync -// {"vfm", &video_family, CONF_TYPE_INT, CONF_MIN, 0, 29, NULL}, // with codec-cfg.c -// {"afm", &audio_fm, CONF_TYPE_STRING, 0, 0, 0, NULL}, {"afm", &audio_fm_list, CONF_TYPE_STRING_LIST, 0, 0, 0, NULL}, {"vfm", &video_fm_list, CONF_TYPE_STRING_LIST, 0, 0, 0, NULL}, -// {"ac", &audio_codec, CONF_TYPE_STRING, 0, 0, 0, NULL}, {"ac", &audio_codec_list, CONF_TYPE_STRING_LIST, 0, 0, 0, NULL}, {"vc", &video_codec_list, CONF_TYPE_STRING_LIST, 0, 0, 0, NULL}, From 22fc61ae812bdca4d4a251b8bcf9bac60e6def06 Mon Sep 17 00:00:00 2001 From: diego Date: Tue, 25 May 2010 11:36:55 +0000 Subject: [PATCH 18/55] cosmetics: vertical alignment in msg module help output git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31215 b3059339-0415-0410-9bf9-f77b7e298cf2 --- cfg-common.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cfg-common.h b/cfg-common.h index 272a60c639..f910adc5fe 100644 --- a/cfg-common.h +++ b/cfg-common.h @@ -314,10 +314,10 @@ const m_option_t msgl_config[]={ " global - common player errors/information\n" " cplayer - console player (mplayer.c)\n" " gplayer - gui player\n" - " vo - libvo\n" - " ao - libao\n" + " vo - libvo\n" + " ao - libao\n" " demuxer - demuxer.c (general stuff)\n" - " ds - demux stream (add/read packet etc)\n" + " ds - demux stream (add/read packet etc)\n" " demux - fileformat-specific stuff (demux_*.c)\n" " header - fileformat-specific header (*header.c)\n" " avsync - mplayer.c timer stuff\n" @@ -328,14 +328,14 @@ const m_option_t msgl_config[]={ " seek - seeking code\n" " win32 - win32 dll stuff\n" " open - open.c (stream opening)\n" - " dvd - open.c (DVD init/read/seek)\n" + " dvd - open.c (DVD init/read/seek)\n" " parsees - parse_es.c (mpeg stream parser)\n" " lirc - lirc_mp.c and input lirc driver\n" " stream - stream.c\n" " cache - cache2.c\n" " mencoder\n" " xacodec - XAnim codecs\n" - " tv - TV input subsystem\n" + " tv - TV input subsystem\n" " osdep - OS-dependent parts\n" " spudec - spudec.c\n" " playtree - Playtree handling (playtree.c, playtreeparser.c)\n" From c15bc5206ef66146e1068c2ec0fad11c4bedabf7 Mon Sep 17 00:00:00 2001 From: diego Date: Tue, 25 May 2010 11:37:53 +0000 Subject: [PATCH 19/55] whitespace cosmetics: fix indentation git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31216 b3059339-0415-0410-9bf9-f77b7e298cf2 --- codec-cfg.c | 126 ++++++++++++++++++++++++++-------------------------- 1 file changed, 63 insertions(+), 63 deletions(-) diff --git a/codec-cfg.c b/codec-cfg.c index 0828e0ea53..eba5aaa877 100644 --- a/codec-cfg.c +++ b/codec-cfg.c @@ -154,75 +154,75 @@ static int add_to_format(char *s, char *alias,unsigned int *fourcc, unsigned int return 1; } - static const struct { - const char *name; - const unsigned int num; - } fmt_table[] = { - // note: due to parser deficiencies/simplicity, if one format - // name matches the beginning of another, the longer one _must_ - // come first in this list. - {"YV12", IMGFMT_YV12}, - {"I420", IMGFMT_I420}, - {"IYUV", IMGFMT_IYUV}, - {"NV12", IMGFMT_NV12}, - {"NV21", IMGFMT_NV21}, - {"YVU9", IMGFMT_YVU9}, - {"IF09", IMGFMT_IF09}, - {"444P16LE", IMGFMT_444P16_LE}, - {"444P16BE", IMGFMT_444P16_BE}, - {"422P16LE", IMGFMT_422P16_LE}, - {"422P16BE", IMGFMT_422P16_BE}, - {"420P16LE", IMGFMT_420P16_LE}, - {"420P16BE", IMGFMT_420P16_BE}, - {"444P16", IMGFMT_444P16}, - {"422P16", IMGFMT_422P16}, - {"420P16", IMGFMT_420P16}, - {"420A", IMGFMT_420A}, - {"444P", IMGFMT_444P}, - {"422P", IMGFMT_422P}, - {"411P", IMGFMT_411P}, - {"440P", IMGFMT_440P}, - {"Y800", IMGFMT_Y800}, - {"Y8", IMGFMT_Y8}, +static const struct { + const char *name; + const unsigned int num; +} fmt_table[] = { + // note: due to parser deficiencies/simplicity, if one format + // name matches the beginning of another, the longer one _must_ + // come first in this list. + {"YV12", IMGFMT_YV12}, + {"I420", IMGFMT_I420}, + {"IYUV", IMGFMT_IYUV}, + {"NV12", IMGFMT_NV12}, + {"NV21", IMGFMT_NV21}, + {"YVU9", IMGFMT_YVU9}, + {"IF09", IMGFMT_IF09}, + {"444P16LE", IMGFMT_444P16_LE}, + {"444P16BE", IMGFMT_444P16_BE}, + {"422P16LE", IMGFMT_422P16_LE}, + {"422P16BE", IMGFMT_422P16_BE}, + {"420P16LE", IMGFMT_420P16_LE}, + {"420P16BE", IMGFMT_420P16_BE}, + {"444P16", IMGFMT_444P16}, + {"422P16", IMGFMT_422P16}, + {"420P16", IMGFMT_420P16}, + {"420A", IMGFMT_420A}, + {"444P", IMGFMT_444P}, + {"422P", IMGFMT_422P}, + {"411P", IMGFMT_411P}, + {"440P", IMGFMT_440P}, + {"Y800", IMGFMT_Y800}, + {"Y8", IMGFMT_Y8}, - {"YUY2", IMGFMT_YUY2}, - {"UYVY", IMGFMT_UYVY}, - {"YVYU", IMGFMT_YVYU}, + {"YUY2", IMGFMT_YUY2}, + {"UYVY", IMGFMT_UYVY}, + {"YVYU", IMGFMT_YVYU}, - {"RGB48LE", IMGFMT_RGB48LE}, - {"RGB48BE", IMGFMT_RGB48BE}, - {"RGB4", IMGFMT_RGB4}, - {"RGB8", IMGFMT_RGB8}, - {"RGB15", IMGFMT_RGB15}, - {"RGB16", IMGFMT_RGB16}, - {"RGB24", IMGFMT_RGB24}, - {"RGB32", IMGFMT_RGB32}, - {"BGR4", IMGFMT_BGR4}, - {"BGR8", IMGFMT_BGR8}, - {"BGR15", IMGFMT_BGR15}, - {"BGR16", IMGFMT_BGR16}, - {"BGR24", IMGFMT_BGR24}, - {"BGR32", IMGFMT_BGR32}, - {"RGB1", IMGFMT_RGB1}, - {"BGR1", IMGFMT_BGR1}, + {"RGB48LE", IMGFMT_RGB48LE}, + {"RGB48BE", IMGFMT_RGB48BE}, + {"RGB4", IMGFMT_RGB4}, + {"RGB8", IMGFMT_RGB8}, + {"RGB15", IMGFMT_RGB15}, + {"RGB16", IMGFMT_RGB16}, + {"RGB24", IMGFMT_RGB24}, + {"RGB32", IMGFMT_RGB32}, + {"BGR4", IMGFMT_BGR4}, + {"BGR8", IMGFMT_BGR8}, + {"BGR15", IMGFMT_BGR15}, + {"BGR16", IMGFMT_BGR16}, + {"BGR24", IMGFMT_BGR24}, + {"BGR32", IMGFMT_BGR32}, + {"RGB1", IMGFMT_RGB1}, + {"BGR1", IMGFMT_BGR1}, - {"MPES", IMGFMT_MPEGPES}, - {"ZRMJPEGNI", IMGFMT_ZRMJPEGNI}, - {"ZRMJPEGIT", IMGFMT_ZRMJPEGIT}, - {"ZRMJPEGIB", IMGFMT_ZRMJPEGIB}, + {"MPES", IMGFMT_MPEGPES}, + {"ZRMJPEGNI", IMGFMT_ZRMJPEGNI}, + {"ZRMJPEGIT", IMGFMT_ZRMJPEGIT}, + {"ZRMJPEGIB", IMGFMT_ZRMJPEGIB}, - {"IDCT_MPEG2",IMGFMT_XVMC_IDCT_MPEG2}, - {"MOCO_MPEG2",IMGFMT_XVMC_MOCO_MPEG2}, + {"IDCT_MPEG2",IMGFMT_XVMC_IDCT_MPEG2}, + {"MOCO_MPEG2",IMGFMT_XVMC_MOCO_MPEG2}, - {"VDPAU_MPEG1",IMGFMT_VDPAU_MPEG1}, - {"VDPAU_MPEG2",IMGFMT_VDPAU_MPEG2}, - {"VDPAU_H264",IMGFMT_VDPAU_H264}, - {"VDPAU_WMV3",IMGFMT_VDPAU_WMV3}, - {"VDPAU_VC1",IMGFMT_VDPAU_VC1}, - {"VDPAU_MPEG4",IMGFMT_VDPAU_MPEG4}, + {"VDPAU_MPEG1",IMGFMT_VDPAU_MPEG1}, + {"VDPAU_MPEG2",IMGFMT_VDPAU_MPEG2}, + {"VDPAU_H264",IMGFMT_VDPAU_H264}, + {"VDPAU_WMV3",IMGFMT_VDPAU_WMV3}, + {"VDPAU_VC1",IMGFMT_VDPAU_VC1}, + {"VDPAU_MPEG4",IMGFMT_VDPAU_MPEG4}, - {NULL, 0} - }; + {NULL, 0} +}; static int add_to_inout(char *sfmt, char *sflags, unsigned int *outfmt, From e765b9cd43385050f4a18213a7100435599560e7 Mon Sep 17 00:00:00 2001 From: diego Date: Tue, 25 May 2010 11:39:58 +0000 Subject: [PATCH 20/55] whitespace cosmetics git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31217 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libmpcodecs/ad_libmad.c | 2 +- libmpcodecs/ad_qtaudio.c | 2 +- libmpcodecs/ad_realaud.c | 2 +- libmpcodecs/ad_sample.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libmpcodecs/ad_libmad.c b/libmpcodecs/ad_libmad.c index 103a05f4a9..08dbe72857 100644 --- a/libmpcodecs/ad_libmad.c +++ b/libmpcodecs/ad_libmad.c @@ -24,7 +24,7 @@ #include "ad_internal.h" -static const ad_info_t info = { +static const ad_info_t info = { "libmad mpeg audio decoder", "libmad", "A'rpi", diff --git a/libmpcodecs/ad_qtaudio.c b/libmpcodecs/ad_qtaudio.c index 2ee0c7e8e7..fb308c2d2c 100644 --- a/libmpcodecs/ad_qtaudio.c +++ b/libmpcodecs/ad_qtaudio.c @@ -33,7 +33,7 @@ #include "loader/wine/windef.h" #endif -static const ad_info_t info = { +static const ad_info_t info = { "QuickTime Audio Decoder", "qtaudio", "A'rpi", diff --git a/libmpcodecs/ad_realaud.c b/libmpcodecs/ad_realaud.c index 4317532d9e..1d475f8dda 100644 --- a/libmpcodecs/ad_realaud.c +++ b/libmpcodecs/ad_realaud.c @@ -32,7 +32,7 @@ #include "ad_internal.h" #include "loader/wine/windef.h" -static const ad_info_t info = { +static const ad_info_t info = { "RealAudio decoder", "realaud", "Alex Beregszaszi", diff --git a/libmpcodecs/ad_sample.c b/libmpcodecs/ad_sample.c index d144c57820..69f4b20dfc 100644 --- a/libmpcodecs/ad_sample.c +++ b/libmpcodecs/ad_sample.c @@ -25,7 +25,7 @@ #include "config.h" #include "ad_internal.h" -static const ad_info_t info = { +static const ad_info_t info = { "Sample audio decoder", // name of the driver "sample", // driver name. should be the same as filename without ad_ "A'rpi", // writer/maintainer of _this_ file From 3c1cedaa565572c8fdbb6a2c085aaca0bcc39d6f Mon Sep 17 00:00:00 2001 From: hyc Date: Tue, 25 May 2010 23:07:28 +0000 Subject: [PATCH 21/55] Add support for STREAM_CTRL_SEEK_TO_TIME in ffmpeg streams git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31218 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libmpdemux/demux_lavf.c | 24 +++++++++++++++++++++--- stream/stream_ffmpeg.c | 11 ++++++++++- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/libmpdemux/demux_lavf.c b/libmpdemux/demux_lavf.c index 67374277ed..3305611876 100644 --- a/libmpdemux/demux_lavf.c +++ b/libmpdemux/demux_lavf.c @@ -83,7 +83,8 @@ typedef struct lavf_priv_t{ }lavf_priv_t; static int mp_read(void *opaque, uint8_t *buf, int size) { - stream_t *stream = opaque; + demuxer_t *demuxer = opaque; + stream_t *stream = demuxer->stream; int ret; if(stream_eof(stream)) //needed? @@ -95,7 +96,8 @@ static int mp_read(void *opaque, uint8_t *buf, int size) { } static int64_t mp_seek(void *opaque, int64_t pos, int whence) { - stream_t *stream = opaque; + demuxer_t *demuxer = opaque; + stream_t *stream = demuxer->stream; int64_t current_pos; mp_msg(MSGT_HEADER,MSGL_DBG2,"mp_seek(%p, %"PRId64", %d)\n", stream, pos, whence); if(whence == SEEK_CUR) @@ -123,6 +125,21 @@ static int64_t mp_seek(void *opaque, int64_t pos, int whence) { return pos - stream->start_pos; } +static int64_t mp_read_seek(void *opaque, int stream_idx, int64_t ts, int flags) { + demuxer_t *demuxer = opaque; + stream_t *stream = demuxer->stream; + lavf_priv_t *priv = demuxer->priv; + AVStream *st = priv->avfc->streams[stream_idx]; + int ret; + double pts; + + pts = (double)ts * st->time_base.num / st->time_base.den; + ret = stream_control(stream, STREAM_CTRL_SEEK_TO_TIME, &pts); + if (ret < 0) + ret = AVERROR(ENOSYS); + return ret; +} + static void list_formats(void) { AVInputFormat *fmt; mp_msg(MSGT_DEMUX, MSGL_INFO, "Available lavf input formats:\n"); @@ -503,7 +520,8 @@ static demuxer_t* demux_open_lavf(demuxer_t *demuxer){ av_strlcat(mp_filename, "foobar.dummy", sizeof(mp_filename)); priv->pb = av_alloc_put_byte(priv->buffer, BIO_BUFFER_SIZE, 0, - demuxer->stream, mp_read, NULL, mp_seek); + demuxer, mp_read, NULL, mp_seek); + priv->pb->read_seek = mp_read_seek; priv->pb->is_streamed = !demuxer->stream->end_pos || (demuxer->stream->flags & MP_STREAM_SEEK) != MP_STREAM_SEEK; if(av_open_input_stream(&avfc, priv->pb, mp_filename, priv->avif, &ap)<0){ diff --git a/stream/stream_ffmpeg.c b/stream/stream_ffmpeg.c index 30d63001d0..a5e80eb999 100644 --- a/stream/stream_ffmpeg.c +++ b/stream/stream_ffmpeg.c @@ -49,7 +49,8 @@ static int seek(stream_t *s, off_t newpos) static int control(stream_t *s, int cmd, void *arg) { - int64_t size; + int64_t size, ts; + double pts; switch(cmd) { case STREAM_CTRL_GET_SIZE: size = url_filesize(s->priv); @@ -57,6 +58,14 @@ static int control(stream_t *s, int cmd, void *arg) *(off_t *)arg = size; return 1; } + break; + case STREAM_CTRL_SEEK_TO_TIME: + pts = *(double *)arg; + ts = pts * AV_TIME_BASE; + ts = av_url_read_seek(s->priv, -1, ts, 0); + if (ts >= 0) + return 1; + break; } return STREAM_UNSUPPORTED; } From eacce255b0a462493155f2e85cdd06cf03de0eae Mon Sep 17 00:00:00 2001 From: diego Date: Tue, 25 May 2010 23:09:20 +0000 Subject: [PATCH 22/55] Remove obsolete new policy proposal draft from Michael. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31219 b3059339-0415-0410-9bf9-f77b7e298cf2 --- DOCS/tech/new_policy_proposal.txt | 309 ------------------------------ 1 file changed, 309 deletions(-) delete mode 100644 DOCS/tech/new_policy_proposal.txt diff --git a/DOCS/tech/new_policy_proposal.txt b/DOCS/tech/new_policy_proposal.txt deleted file mode 100644 index d6fbfbc6b3..0000000000 --- a/DOCS/tech/new_policy_proposal.txt +++ /dev/null @@ -1,309 +0,0 @@ -New Policy Draft -Version 20070301 - -Intro: ------- -This document is an attempt to write a new policy as the old is fairly -confusing and easy to misunderstand, its intention is not really to -change the rules but rather to write them down clearer ... -also for simplicity and to prevent flamewars, i would suggest that you -fork this document and propose that fork as alternative if you have a -significant disagreement with me on some part - -Author: -------- -Michael Niedermayer -the authors of the old policy as I liberally copy and pasted from it - -TODO: -add more explanations, justifications and examples -how to become/loose maintainer status -review patches.txt -security/exploit rules ------------------------- - - -1. Definitions --------------- -* MPlayer developer, generally referred to simply as developer in this document - is any person who has a open (not cracked, not suspended) svn write account -* MPlayer leader, generally referred to simply as leader in this document, every - leader is also a developer -* CAN/MUST/SHOULD descriptions ... -* public developer mailing list (mplayer-dev-eng at mplayerhq in hungary) - - -C. Code and SVN Rules ------------------------------ -Renaming/moving/copying files or contents of files - Do not move, rename or copy files of which you are not the maintainer without - discussing it on the public developer mailinglist first! - - Never copy or move a file by using 'svn delete' and 'svn add'. Always use - 'svn move' or 'svn copy' instead in order to preserve history and minimize - the size of diffs. - - To split a file, use 'svn copy' and remove the unneeded lines from each file. - - Don't do a lot of cut'n'paste from one file to another without a very good - reason and discuss it on the mplayer-dev-eng mailing list first. It will make - those changes hard to trace. - - Such actions are useless and treated as cosmetics in 99% of cases, - so try to avoid them. - -Reverting broken commits - There are 2 ways to reverse a change, they differ significantly in what they - do to the svn repository - The recommit old method: - svn merge - svn ci - This simply changes the file(s) back to their old version localy and then - the change is commited as if it is a new change - The svn copy method - svn rm - svn ci - svn cp -r svn://svn.mplayerhq.hu/mplayer/trunk/[/] - svn ci - This simply removes the file and then copies the last good version with - its history over it, this method can only be used to revert the n last - commits but not to revert a bad commit in the middle of its history - Neither method will change the history, checking out an old version will - always return exactly that revision with all its bugs and features. The - difference is that with the svn copy method the broken commit will not be - part of the directly visible history of the revisions after the reversal - So if the change was completely broken like reindenting a file against the - maintainers decision, or a change which mixed functional and cosmetic - changes then it is better if it is not part of the visible history as it - would make it hard to read, review and would also break svn annotate - For the example of a change which mixed functional and cosmetic parts they - should of course be committed again after the reversal but separately, so one - change with the functional stuff and one with the cosmetics - OTOH if the change which you want to reverse was simply buggy but not - totally broken then it should be reversed with svn merge as otherwise - the fact that the change was bad would be hidden - One method to decide which reversal method is best is to ask yourself - if there is any value in seeing the whole bad change and its removal - in SVN vs just seeing a comment that says what has been reversed while - the actual change does not clutter the immediately visible history and - svn annotate. - If you are even just slightly uncertain how to revert something then ask on - the mplayer-dev-eng mailing list. - -Broken code - You must not commit code which breaks MPlayer! (Meaning unfinished but - enabled code which breaks compilation or compiles but does not work.) - You can commit unfinished stuff (for testing etc), but it must be disabled - (#ifdef etc) by default so it does not interfere with other developers' - work. - -Testing code - You don't have to over-test things. If it works for you, and you think it - should work for others, too, then commit. If your code has problems - (portability, exploits compiler bugs, unusual environment etc) they will be - reported and eventually fixed. - -Splitting changes - Do not commit unrelated changes together, split them into self-contained - pieces. Also dont forget that if part B depends on part A but A doesnt - depend on B, then A can and should be commited first and seperately from B. - Keeping changes well split into self contained parts makes reviewing and - understanding them on svn log at the time of commit and later when - debugging a bug much easier. - Also if you have doubt about spliting or not spliting, dont hesitate to - ask/disscuss it on the developer mailing list. - -4. Do not change behavior of the program (renaming options etc) or - remove functionality from the code without approval in a discussion on - the mplayer-dev-eng mailing list. - - -5. Do not commit changes to the build system (Makefiles, configure script) - which change behaviour, defaults etc, without asking first. The same - applies to compiler warning fixes, trivial looking fixes and to code - maintained by other developers. We usually have a reason for doing things - the way we do. Send your changes as patches to the mplayer-dev-eng mailing - list, and if the code maintainers say OK, you may commit. This does not - apply to files you wrote and/or maintain. - - -Cosmetics - We refuse source indentation and other cosmetic changes if they are mixed - with functional changes, such commits will be reverted. Every - developer has his own indentation style, you should not change it. Of course - if you (re)write something, you can use your own style... (Many projects - force a given indentation style - we don't.) If you really need to make - indentation changes (try to avoid this), separate them strictly from real - changes. - - NOTE: If you had to put if()@{ .. @} over a large (> 5 lines) chunk of code, - then either do NOT change the indentation of the inner part within (don't - move it to the right)! or do so in a separate commit - - -Commit log message - Always fill out the commit log message. Describe in a few lines what you - changed and why. You can refer to mailing list postings if you fix a - particular bug. Comments such as "fixed!" or "Changed it." are unacceptable. - - -Applying patches - If you apply a patch by someone else, include the name and email address in - the log message. Since the mplayer-cvslog mailing list is publicly - archived you should add some spam protection to the email address. Send an - answer to mplayer-dev-eng (or wherever you got the patch from) saying that - you applied the patch. If the patch contains a documentation change, commit - that as well; do not leave it to the documentation maintainers. - - -messing with other developers code - Do NOT commit to code actively maintained by others without permission. Send - a patch to mplayer-dev-eng instead. - - -Subscribe to svnlog - Subscribe to the mplayer-cvslog mailing list. The diffs of all commits - are sent there and reviewed by all the other developers. Bugs and possible - improvements or general questions regarding commits are discussed there. We - expect you to react if problems with your code are uncovered. - - -Documentation - Update the documentation if you change behavior or add features. If you are - unsure how best to do this, send a patch to mplayer-docs, the documentation - maintainers will review and commit your stuff. - - -Controversial changes - Always send a patch to the mplayer-dev-eng mailing list before committing - if you suspect that the change is going to be controversial. Based on past - experience, these changes are likely to be controversial: - - feature removal, even if obsolete - - changes to "special" output messages (like the "Core dumped ;)" message) - - verbosity changes from default (info) level - - changes to "historical" parts of docs and webpages - - use of internal or external libraries - - changes to the internal architecture - - non trivial changes to very fundamental parts of mplayer - - -Public discussions - Try to keep important discussions and requests (also) on the - mplayer-dev-eng mailing list, so that all developers can benefit from them. - IRC is good for quick discussions, but nobody is there 24/7. - also subscribe to the public developer mailing list - - -Compiler Warning fixes - Do not change code to hide warnings without ensuring that the underlaying - logic is correct and thus the warning was inappropriate - - -Patches - read and follow patches.txt when sending patches for mplayer - - -Insults - Do not insult other people in relation to mplayer on any public mailing - list, that is calling code from someone else a pile of broken shit is - perfectly fine but calling the developer herself a retarded f*cking moron - is not acceptable - - -Forking - People disagreeing with the developers or leaders may fork the project, - the leaders MUST in that case provide a svn dump with all history if - the person forking wants one - - -Communicating passwords - Developers who have provided a public gpg key shall only receive - passwords or other sensitive information related to mplayer encrypted - with their gpg key or in another secure way - - -V. Votes --------- -Its inevitable that some things will be decided by voting, votes in the past -have due to total lack of rules been problematic for example as many people -rather wrote long texts and voted based on some condition instead of saying -a clear yes or no, still its important that people can vote based on a -condition -The result of a vote is binding for all developers and leaders, though of -course they can leave the project and thus cease to be a developer or leader -any time - -Vs. Starting a vote -Any single developer can start a vote, to do so she has to send a mail to the -public developer mailing list of the project with a subject containing [VOTE] -and a clear and concise description, a longer descrition can be in the body -of the mail - -Vp. Proposing an option (point on the ballot, better term?) -Any single developer can propose an option up to 7 days after a vote has -been started, to do so she has to reply to the original vote mail on the -public developer mailing list and clearly, concise and unmistakably describe -the option and place [VOTE-OPTION] instead of [VOTE] in the subject -in addition to proposed options, there always exists the default option -of doing nothing -options can be conditional on anything which at the end of the vote can -be clearly and unmistakably be answered with true or false - -Vv. Voting -Any developer can cast a vote up to 10 days days after a vote has been -started, to do so she has to reply to the original vote mail on the -public developer mailing list and rate options each with an integer -unrated options shall be counted equal to the default option -Any leader can cast a veto against any option except the default up to 10 days -days after a vote has been started, to do so she has to reply to the original -vote mail on the public developer mailing list and replace -[VOTE] by [VOTE-VETO] -Developers and leaders who use gpg/pgp MUST sign their votes and vetoes - -Vc. Counting votes -The person starting the vote has to count the votes and vetoes and publish -the result on the public developer mailing list as reply to the original vote -with [VOTE-RESULTS] instead of [VOTE] in the subject -Vcv. Counting vetoes -if the majority of leaders that is yes >= no && yes>0 cast a veto against an -option then it has a required supermajority of 2:1 otherwise it has a -required supermajority of 0:1 and in either case no quorum requirement -Vcc. the votes shall be counted by using the Condorcet/Clone Proof SSD -Voting Method described in http://www.debian.org/devel/constitution A.6 - -Reasoning behind avoiding of a quorum and majority requirement except in -the case of vetoes -short awnser its stupid and has catastrophical failure modes -example of one such failure mode, lets assume a 1:1 majority requirement -as debian uses by default, there are 101 developers who vote, there are -3 options A,B and D the default (doing nothing / further discussions) -50 developers prefer A over B and B over discussions (A>B>D) -50 developers prefer discussions over A and A over B (D>A>B) -1 developer prefers B over discussions and discussions over A (B>D>A) -in this case A is approved by 50 of 101 developers and is droped due to -the lack of majority, B is approved by 51 of 101 developers and is not -furthermore B wins even though 100 of 101 developers prefer A over B - - -S. Changes to developer and Leader status ----------------------------------------- -The majority of leaders, that is yes>no can give and take away -developer and leader status to people -furthermore any developer or leader can step back and thus loose -his leader and or developer status -People disagreeing with the leaders are free to fork the project -new developers should be asked for real name, public gpg key, phone -number and email addresses, none of this is mandatory though, it is asked -so as to be able to contact the developer if the need arises and one -contact method fails - - -O. Violations -------------- -Any leader can after at least one leader has warned another developer -due to breaking policy, suspend his account if he repeats the violation -Ow. A policy violation warning MUST be CCed to the developer who violated -the policy - - -We think our rules are not too hard. If you have comments, contact us. From ab1c858071ac93fc4736582f259b580c4734cc71 Mon Sep 17 00:00:00 2001 From: diego Date: Tue, 25 May 2010 23:41:30 +0000 Subject: [PATCH 23/55] Add support for decoding VP8 through libvpx wrapper in FFmpeg. patch by James Zern, jzern google com git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31220 b3059339-0415-0410-9bf9-f77b7e298cf2 --- Changelog | 1 + configure | 28 ++++++++++++++++++++++++++++ etc/codecs.conf | 8 ++++++++ 3 files changed, 37 insertions(+) diff --git a/Changelog b/Changelog index b15c7fb655..9a24914a59 100644 --- a/Changelog +++ b/Changelog @@ -17,6 +17,7 @@ MPlayer (1.0) * JPEG 2000 support via OpenJPEG * internal liba52 copy removed * CineForm HD (CFHD) via binary DLL + * VP8 decoding through libvpx wrapper in FFmpeg Demuxers: * support for TrueHD in Blu-ray streams in libmpdemux diff --git a/configure b/configure index 021708e83d..0e851da0be 100755 --- a/configure +++ b/configure @@ -299,6 +299,7 @@ Codecs: --disable-libdirac-lavc disable Dirac in libavcodec [autodetect] --disable-libschroedinger-lavc disable Dirac in libavcodec (Schroedinger decoder) [autodetect] + --disable-libvpx-lavc disable libvpx in libavcodec [autodetect] --disable-libnut disable libnut [autodetect] --disable-libavutil_a disable static libavutil [autodetect] --disable-libavcodec_a disable static libavcodec [autodetect] @@ -693,6 +694,7 @@ _x264=auto _x264_lavc=auto _libdirac_lavc=auto _libschroedinger_lavc=auto +_libvpx_lavc=auto _libnut=auto _lirc=auto _lircc=auto @@ -1137,6 +1139,8 @@ for ac_option do --disable-libdirac-lavc) _libdirac_lavc=no ;; --enable-libschroedinger-lavc) _libschroedinger_lavc=yes ;; --disable-libschroedinger-lavc) _libschroedinger_lavc=no ;; + --enable-libvpx-lavc) _libvpx_lavc=yes ;; + --disable-libvpx-lavc) _libvpx_lavc=no ;; --enable-libnut) _libnut=yes ;; --disable-libnut) _libnut=no ;; --enable-libavutil_a) _libavutil_a=yes ;; @@ -7596,6 +7600,30 @@ else fi echores "$_libschroedinger_lavc" +echocheck "libvpx" +if test "$_libvpx_lavc" = auto; then + _libvpx_lavc=no + if test "$_libavcodec_a" != yes; then + res_comment="libavcodec (static) is required by libvpx, sorry" + else + cat > $TMPC << EOF +#include +#include +int main(void) { vpx_codec_dec_init(NULL, &vpx_codec_vp8_dx_algo, NULL, 0); return 0; } +EOF + cc_check -lvpx && _libvpx_lavc=yes && extra_ldflags="$extra_ldflags -lvpx" + fi +fi +if test "$_libvpx_lavc" = yes ; then + def_libvpx_lavc='#define CONFIG_LIBVPX 1' + _libavdecoders="$_libavdecoders LIBVPX_DECODER" + codecmodules="libvpx $codecmodules" +else + def_libvpx_lavc='#define CONFIG_LIBVPX 0' + nocodecmodules="libvpx $nocodecmodules" +fi +echores "$_libvpx_lavc" + echocheck "libnut" if test "$_libnut" = auto ; then cat > $TMPC << EOF diff --git a/etc/codecs.conf b/etc/codecs.conf index 3b1e356662..23bff5dc8e 100644 --- a/etc/codecs.conf +++ b/etc/codecs.conf @@ -2173,6 +2173,14 @@ videocodec vp7 out YUY2 out BGR32,BGR24 +videocodec fflibvpx + info "FFmpeg wrapper for libvpx/VP8" + status working + fourcc VP80 + driver ffmpeg + dll "libvpx" + out YV12 + videocodec mwv1 info "Motion Wavelets" status working From 7bb3c3b68129d9429bba59c8b8de0741e6a54153 Mon Sep 17 00:00:00 2001 From: diego Date: Wed, 26 May 2010 00:47:22 +0000 Subject: [PATCH 24/55] Add missing RGB12 version of the fast OSD table. patch by Janusz Krzysztofik, jkrzyszt tis.icnet pl git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31221 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libvo/osd.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libvo/osd.c b/libvo/osd.c index 54854c785f..992ffc01f3 100644 --- a/libvo/osd.c +++ b/libvo/osd.c @@ -284,6 +284,7 @@ void vo_draw_alpha_rgb32(int w,int h, unsigned char* src, unsigned char *srca, i } #ifdef FAST_OSD_TABLE +static unsigned short fast_osd_12bpp_table[256]; static unsigned short fast_osd_15bpp_table[256]; static unsigned short fast_osd_16bpp_table[256]; #endif @@ -292,6 +293,7 @@ void vo_draw_alpha_init(void){ #ifdef FAST_OSD_TABLE int i; for(i=0;i<256;i++){ + fast_osd_12bpp_table[i]=((i>>4)<< 8)|((i>>4)<<4)|(i>>4); fast_osd_15bpp_table[i]=((i>>3)<<10)|((i>>3)<<5)|(i>>3); fast_osd_16bpp_table[i]=((i>>3)<<11)|((i>>2)<<5)|(i>>3); } From e43d1dd2472a378d96d1da9d81699791e3de4b9c Mon Sep 17 00:00:00 2001 From: cehoyos Date: Wed, 26 May 2010 10:05:36 +0000 Subject: [PATCH 25/55] Both XVID and VDPAU decode our SIPP sample better than current libavcodec. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31222 b3059339-0415-0410-9bf9-f77b7e298cf2 --- etc/codecs.conf | 2 ++ 1 file changed, 2 insertions(+) diff --git a/etc/codecs.conf b/etc/codecs.conf index 23bff5dc8e..515f313ba6 100644 --- a/etc/codecs.conf +++ b/etc/codecs.conf @@ -1037,6 +1037,7 @@ videocodec ffodivxvdpau fourcc M4T3,DMK2,DIGI,INMC fourcc EPHV,SN40 fourcc uldx,ULDX,VSPX + fourcc SIPP ; Samsung SHR-6040 driver ffmpeg dll mpeg4_vdpau out VDPAU_MPEG4 @@ -1090,6 +1091,7 @@ videocodec xvid fourcc EPHV,SN40 fourcc uldx,ULDX,VSPX format 0x10000004 ; mpeg 4 es + fourcc SIPP ; Samsung SHR-6040 driver xvid out YV12 out I420 From d304c1d56c5ffc242a0ffefcc2a1c9fedb12f56c Mon Sep 17 00:00:00 2001 From: reimar Date: Wed, 26 May 2010 17:27:38 +0000 Subject: [PATCH 26/55] Disable waking the cache process up via a signal, it currently causes read errors due to not handling EINTR. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31223 b3059339-0415-0410-9bf9-f77b7e298cf2 --- stream/cache2.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/stream/cache2.c b/stream/cache2.c index 51989ebd2a..fef316f627 100644 --- a/stream/cache2.c +++ b/stream/cache2.c @@ -102,7 +102,10 @@ static void cache_wakeup(stream_t *s) { #if FORKED_CACHE // signal process to wake up immediately - kill(s->cache_pid, SIGUSR1); + // Disabled for now since it causes incorrect EOFs + // due to interrupting read syscalls - this should be + // fixed instead though +// kill(s->cache_pid, SIGUSR1); #endif } From 328306708f6687e9cf43a32930b252bc18ba851f Mon Sep 17 00:00:00 2001 From: reimar Date: Wed, 26 May 2010 17:56:11 +0000 Subject: [PATCH 27/55] Re-enable wakeup-on-signal for cache process. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31224 b3059339-0415-0410-9bf9-f77b7e298cf2 --- stream/cache2.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/stream/cache2.c b/stream/cache2.c index fef316f627..e936e47dca 100644 --- a/stream/cache2.c +++ b/stream/cache2.c @@ -102,10 +102,7 @@ static void cache_wakeup(stream_t *s) { #if FORKED_CACHE // signal process to wake up immediately - // Disabled for now since it causes incorrect EOFs - // due to interrupting read syscalls - this should be - // fixed instead though -// kill(s->cache_pid, SIGUSR1); + kill(s->cache_pid, SIGUSR1); #endif } @@ -356,11 +353,20 @@ static void cache_mainloop(cache_vars_t *s) { int sleep_count = 0; do { if (!cache_fill(s)) { +#if FORKED_CACHE + // Let signal wake us up, we cannot leave this + // enabled since we do not handle EINTR in most places. + // This might need extra code to work on BSD. + signal(SIGUSR1, dummy_sighandler); +#endif if (sleep_count < INITIAL_FILL_USLEEP_COUNT) { sleep_count++; usec_sleep(INITIAL_FILL_USLEEP_TIME); } else usec_sleep(FILL_USLEEP_TIME); // idle +#if FORKED_CACHE + signal(SIGUSR1, SIG_IGN); +#endif } else sleep_count = 0; // cache_stats(s->cache_data); @@ -449,7 +455,6 @@ err_out: use_gui = 0; // mp_msg may not use gui stuff in forked code #endif signal(SIGTERM,exit_sighandler); // kill - signal(SIGUSR1, dummy_sighandler); // wakeup cache_mainloop(s); // make sure forked code never leaves this function exit(0); From 1e0b9a97fd840c547bc22591ce225f998d0cf3c5 Mon Sep 17 00:00:00 2001 From: reimar Date: Wed, 26 May 2010 18:01:38 +0000 Subject: [PATCH 28/55] Switch ogg demuxing to lavf by default. This has the side-effect of using fftheora by default instead of theora, which possibly should be changed. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31225 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libmpdemux/demux_lavf.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libmpdemux/demux_lavf.c b/libmpdemux/demux_lavf.c index 3305611876..dea34b72c2 100644 --- a/libmpdemux/demux_lavf.c +++ b/libmpdemux/demux_lavf.c @@ -216,6 +216,7 @@ static const char * const preferred_list[] = { "mpc", "mpc8", "mxf", + "ogg", "swf", "vqf", "w64", From c36de0867fc576ad5fd58fc28bd5fe3322579f36 Mon Sep 17 00:00:00 2001 From: reimar Date: Wed, 26 May 2010 18:23:43 +0000 Subject: [PATCH 29/55] Retry reading even if we hit eof before. This allows playing growing files even with a large cache. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31226 b3059339-0415-0410-9bf9-f77b7e298cf2 --- stream/cache2.c | 4 ++-- stream/stream.c | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/stream/cache2.c b/stream/cache2.c index e936e47dca..533781104b 100644 --- a/stream/cache2.c +++ b/stream/cache2.c @@ -225,7 +225,7 @@ static int cache_fill(cache_vars_t *s) //memcpy(&s->buffer[pos],s->stream->buffer,len); // avoid this extra copy! // .... len=stream_read(s->stream,&s->buffer[pos],space); - if(!len) s->eof=1; + s->eof= !len; s->max_filepos+=len; if(pos+len>=s->buffer_size){ @@ -477,7 +477,6 @@ static void *ThreadProc( void *s ){ int cache_stream_fill_buffer(stream_t *s){ int len; - if(s->eof){ s->buf_pos=s->buf_len=0; return 0; } if(!s->cache_pid) return stream_fill_buffer(s); // cache_stats(s->cache_data); @@ -488,6 +487,7 @@ int cache_stream_fill_buffer(stream_t *s){ //printf("cache_stream_fill_buffer->read -> %d\n",len); if(len<=0){ s->eof=1; s->buf_pos=s->buf_len=0; return 0; } + s->eof=0; s->buf_pos=0; s->buf_len=len; s->pos+=len; diff --git a/stream/stream.c b/stream/stream.c index d4abc69343..cdd9713a20 100644 --- a/stream/stream.c +++ b/stream/stream.c @@ -263,7 +263,7 @@ stream_t* open_output_stream(const char* filename, char** options) { int stream_fill_buffer(stream_t *s){ int len; - if (/*s->fd == NULL ||*/ s->eof) { return 0; } + // we will retry even if we already reached EOF previously. switch(s->type){ case STREAMTYPE_STREAM: #ifdef CONFIG_NETWORK @@ -285,6 +285,9 @@ int stream_fill_buffer(stream_t *s){ len= s->fill_buffer ? s->fill_buffer(s,s->buffer,STREAM_BUFFER_SIZE) : 0; } if(len<=0){ s->eof=1; return 0; } + // When reading succeeded we are obviously not at eof. + // This e.g. avoids issues with eof getting stuck when lavf seeks in MPEG-TS + s->eof=0; s->buf_pos=0; s->buf_len=len; s->pos+=len; From ca04a9c8ea77bcaaa0118646bcd0137c5da15ad3 Mon Sep 17 00:00:00 2001 From: diego Date: Thu, 27 May 2010 09:54:11 +0000 Subject: [PATCH 30/55] cosmetics: K&R coding style git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31227 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libmpcodecs/vd.c | 433 +++++++++++++++++++++++++---------------------- 1 file changed, 233 insertions(+), 200 deletions(-) diff --git a/libmpcodecs/vd.c b/libmpcodecs/vd.c index 096de92806..2aaeb65f65 100644 --- a/libmpcodecs/vd.c +++ b/libmpcodecs/vd.c @@ -67,71 +67,71 @@ extern const vd_functions_t mpcodecs_vd_qtvideo; * libraries and decoders requiring binary support. */ const vd_functions_t * const mpcodecs_vd_drivers[] = { - &mpcodecs_vd_null, + &mpcodecs_vd_null, #ifdef CONFIG_LIBAVCODEC - &mpcodecs_vd_ffmpeg, + &mpcodecs_vd_ffmpeg, #endif #ifdef CONFIG_OGGTHEORA - &mpcodecs_vd_theora, + &mpcodecs_vd_theora, #endif #ifdef CONFIG_WIN32DLL - &mpcodecs_vd_dshow, - &mpcodecs_vd_dmo, - &mpcodecs_vd_vfw, - &mpcodecs_vd_vfwex, + &mpcodecs_vd_dshow, + &mpcodecs_vd_dmo, + &mpcodecs_vd_vfw, + &mpcodecs_vd_vfwex, #endif - &mpcodecs_vd_lzo, - &mpcodecs_vd_raw, - &mpcodecs_vd_hmblck, + &mpcodecs_vd_lzo, + &mpcodecs_vd_raw, + &mpcodecs_vd_hmblck, #ifdef CONFIG_XANIM - &mpcodecs_vd_xanim, + &mpcodecs_vd_xanim, #endif #ifdef CONFIG_PNG - &mpcodecs_vd_mpng, + &mpcodecs_vd_mpng, #endif #ifdef CONFIG_JPEG - &mpcodecs_vd_ijpg, + &mpcodecs_vd_ijpg, #endif - &mpcodecs_vd_mtga, - &mpcodecs_vd_sgi, + &mpcodecs_vd_mtga, + &mpcodecs_vd_sgi, #ifdef CONFIG_LIBMPEG2 - &mpcodecs_vd_libmpeg2, + &mpcodecs_vd_libmpeg2, #endif - &mpcodecs_vd_mpegpes, + &mpcodecs_vd_mpegpes, #ifdef CONFIG_ZR - &mpcodecs_vd_zrmjpeg, + &mpcodecs_vd_zrmjpeg, #endif #ifdef CONFIG_REALCODECS - &mpcodecs_vd_realvid, + &mpcodecs_vd_realvid, #endif #ifdef CONFIG_XVID4 - &mpcodecs_vd_xvid, + &mpcodecs_vd_xvid, #endif #ifdef CONFIG_LIBDV095 - &mpcodecs_vd_libdv, + &mpcodecs_vd_libdv, #endif #ifdef CONFIG_QTX_CODECS - &mpcodecs_vd_qtvideo, + &mpcodecs_vd_qtvideo, #endif /* Please do not add any new decoders here. If you want to implement a new * decoder, add it to libavcodec, except for wrappers around external * libraries and decoders requiring binary support. */ - NULL + NULL }; #include "libvo/video_out.h" // libvo opts: -int fullscreen=0; -int vidmode=0; -int softzoom=0; -int flip=-1; -int opt_screen_size_x=0; -int opt_screen_size_y=0; -float screen_size_xy=0; -float movie_aspect=-1.0; -int vo_flags=0; -int vd_use_slices=1; +int fullscreen = 0; +int vidmode = 0; +int softzoom = 0; +int flip = -1; +int opt_screen_size_x = 0; +int opt_screen_size_y = 0; +float screen_size_xy = 0; +float movie_aspect = -1.0; +int vo_flags = 0; +int vd_use_slices = 1; /** global variables for gamma, brightness, contrast, saturation and hue modified by mplayer.c and gui/mplayer/gtk/eq.c: @@ -144,204 +144,230 @@ int vo_gamma_contrast = 1000; int vo_gamma_saturation = 1000; int vo_gamma_hue = 1000; -extern const vd_functions_t* mpvdec; // FIXME! +extern const vd_functions_t *mpvdec; // FIXME! #define SCREEN_SIZE_X 1 #define SCREEN_SIZE_Y 1 -int mpcodecs_config_vo(sh_video_t *sh, int w, int h, unsigned int preferred_outfmt){ - int i,j; - unsigned int out_fmt=0; - int screen_size_x=0;//SCREEN_SIZE_X; - int screen_size_y=0;//SCREEN_SIZE_Y; - vf_instance_t* vf=sh->vfilter,*sc=NULL; - int palette=0; - int vocfg_flags=0; +int mpcodecs_config_vo(sh_video_t *sh, int w, int h, + unsigned int preferred_outfmt) +{ + int i, j; + unsigned int out_fmt = 0; + int screen_size_x = 0; //SCREEN_SIZE_X; + int screen_size_y = 0; //SCREEN_SIZE_Y; + vf_instance_t *vf = sh->vfilter, *sc = NULL; + int palette = 0; + int vocfg_flags = 0; - if(w) - sh->disp_w=w; - if(h) - sh->disp_h=h; + if (w) + sh->disp_w = w; + if (h) + sh->disp_h = h; - if(!sh->disp_w || !sh->disp_h) - return 0; + if (!sh->disp_w || !sh->disp_h) + return 0; mp_msg(MSGT_DECVIDEO, MSGL_V, - "VDec: vo config request - %d x %d (preferred colorspace: %s)\n", - w, h, vo_format_name(preferred_outfmt)); + "VDec: vo config request - %d x %d (preferred colorspace: %s)\n", w, + h, vo_format_name(preferred_outfmt)); // if(!vf) return 1; // temp hack - if(get_video_quality_max(sh)<=0 && divx_quality){ - // user wants postprocess but no pp filter yet: - sh->vfilter=vf=vf_open_filter(vf,"pp",NULL); + if (get_video_quality_max(sh) <= 0 && divx_quality) { + // user wants postprocess but no pp filter yet: + sh->vfilter = vf = vf_open_filter(vf, "pp", NULL); } - // check if libvo and codec has common outfmt (no conversion): -csp_again: + csp_again: - if( mp_msg_test(MSGT_DECVIDEO,MSGL_V) ){ - vf_instance_t* f=vf; - mp_msg(MSGT_DECVIDEO,MSGL_V,"Trying filter chain:"); - for(f = vf ; f ; f = f->next) - mp_msg(MSGT_DECVIDEO,MSGL_V," %s",f->info->name); - mp_msg(MSGT_DECVIDEO,MSGL_V,"\n"); + if (mp_msg_test(MSGT_DECVIDEO, MSGL_V)) { + vf_instance_t *f = vf; + mp_msg(MSGT_DECVIDEO, MSGL_V, "Trying filter chain:"); + for (f = vf; f; f = f->next) + mp_msg(MSGT_DECVIDEO, MSGL_V, " %s", f->info->name); + mp_msg(MSGT_DECVIDEO, MSGL_V, "\n"); } - j=-1; - for(i=0;icodec->outfmt[i]; - if(out_fmt==(unsigned int)0xFFFFFFFF) continue; - flags=vf->query_format(vf,out_fmt); - mp_msg(MSGT_CPLAYER,MSGL_DBG2,"vo_debug: query(%s) returned 0x%X (i=%d) \n",vo_format_name(out_fmt),flags,i); - if((flags&VFCAP_CSP_SUPPORTED_BY_HW) || (flags&VFCAP_CSP_SUPPORTED && j<0)){ - // check (query) if codec really support this outfmt... - sh->outfmtidx=j; // pass index to the control() function this way - if(mpvdec->control(sh,VDCTRL_QUERY_FORMAT,&out_fmt)==CONTROL_FALSE){ - mp_msg(MSGT_CPLAYER,MSGL_DBG2,"vo_debug: codec query_format(%s) returned FALSE\n",vo_format_name(out_fmt)); - continue; - } - j=i; vo_flags=flags; if(flags&VFCAP_CSP_SUPPORTED_BY_HW) break; - } else - if(!palette && !(flags&(VFCAP_CSP_SUPPORTED_BY_HW|VFCAP_CSP_SUPPORTED)) && (out_fmt==IMGFMT_RGB8||out_fmt==IMGFMT_BGR8)){ - sh->outfmtidx=j; // pass index to the control() function this way - if(mpvdec->control(sh,VDCTRL_QUERY_FORMAT,&out_fmt)!=CONTROL_FALSE) - palette=1; - } + j = -1; + for (i = 0; i < CODECS_MAX_OUTFMT; i++) { + int flags; + out_fmt = sh->codec->outfmt[i]; + if (out_fmt == (unsigned int) 0xFFFFFFFF) + continue; + flags = vf->query_format(vf, out_fmt); + mp_msg(MSGT_CPLAYER, MSGL_DBG2, + "vo_debug: query(%s) returned 0x%X (i=%d) \n", + vo_format_name(out_fmt), flags, i); + if ((flags & VFCAP_CSP_SUPPORTED_BY_HW) + || (flags & VFCAP_CSP_SUPPORTED && j < 0)) { + // check (query) if codec really support this outfmt... + sh->outfmtidx = j; // pass index to the control() function this way + if (mpvdec->control(sh, VDCTRL_QUERY_FORMAT, &out_fmt) == + CONTROL_FALSE) { + mp_msg(MSGT_CPLAYER, MSGL_DBG2, + "vo_debug: codec query_format(%s) returned FALSE\n", + vo_format_name(out_fmt)); + continue; + } + j = i; + vo_flags = flags; + if (flags & VFCAP_CSP_SUPPORTED_BY_HW) + break; + } else if (!palette + && !(flags & + (VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_CSP_SUPPORTED)) + && (out_fmt == IMGFMT_RGB8 || out_fmt == IMGFMT_BGR8)) { + sh->outfmtidx = j; // pass index to the control() function this way + if (mpvdec->control(sh, VDCTRL_QUERY_FORMAT, &out_fmt) != + CONTROL_FALSE) + palette = 1; + } } - if(j<0){ - // TODO: no match - we should use conversion... - if(strcmp(vf->info->name,"scale") && palette!=-1){ - mp_msg(MSGT_DECVIDEO,MSGL_INFO,MSGTR_CouldNotFindColorspace); - sc=vf=vf_open_filter(vf,"scale",NULL); - goto csp_again; - } else - if(palette==1){ - mp_msg(MSGT_DECVIDEO,MSGL_V,"vd: Trying -vf palette...\n"); - palette=-1; - vf=vf_open_filter(vf,"palette",NULL); - goto csp_again; - } else - { // sws failed, if the last filter (vf_vo) support MPEGPES try to append vf_lavc - vf_instance_t* vo, *vp = NULL, *ve, *vpp = NULL; - // Remove the scale filter if we added it ourself - if(vf == sc) { - ve = vf; - vf = vf->next; - vf_uninit_filter(ve); - } - // Find the last filter (vf_vo) - for(vo = vf ; vo->next ; vo = vo->next) { - vpp = vp; - vp = vo; - } - if(vo->query_format(vo,IMGFMT_MPEGPES) && (!vp || (vp && strcmp(vp->info->name,"lavc")))) { - ve = vf_open_filter(vo,"lavc",NULL); - if(vp) vp->next = ve; - else vf = ve; - goto csp_again; - } - if (vp && !strcmp(vp->info->name,"lavc")) { - if (vpp) vpp->next = vo; - else vf = vo; - vf_uninit_filter(vp); - } - } - mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_VOincompCodec); - sh->vf_initialized=-1; - return 0; // failed + if (j < 0) { + // TODO: no match - we should use conversion... + if (strcmp(vf->info->name, "scale") && palette != -1) { + mp_msg(MSGT_DECVIDEO, MSGL_INFO, MSGTR_CouldNotFindColorspace); + sc = vf = vf_open_filter(vf, "scale", NULL); + goto csp_again; + } else if (palette == 1) { + mp_msg(MSGT_DECVIDEO, MSGL_V, "vd: Trying -vf palette...\n"); + palette = -1; + vf = vf_open_filter(vf, "palette", NULL); + goto csp_again; + } else { // sws failed, if the last filter (vf_vo) support MPEGPES try to append vf_lavc + vf_instance_t *vo, *vp = NULL, *ve, *vpp = NULL; + // Remove the scale filter if we added it ourself + if (vf == sc) { + ve = vf; + vf = vf->next; + vf_uninit_filter(ve); + } + // Find the last filter (vf_vo) + for (vo = vf; vo->next; vo = vo->next) { + vpp = vp; + vp = vo; + } + if (vo->query_format(vo, IMGFMT_MPEGPES) + && (!vp || (vp && strcmp(vp->info->name, "lavc")))) { + ve = vf_open_filter(vo, "lavc", NULL); + if (vp) + vp->next = ve; + else + vf = ve; + goto csp_again; + } + if (vp && !strcmp(vp->info->name, "lavc")) { + if (vpp) + vpp->next = vo; + else + vf = vo; + vf_uninit_filter(vp); + } + } + mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_VOincompCodec); + sh->vf_initialized = -1; + return 0; // failed } - out_fmt=sh->codec->outfmt[j]; + out_fmt = sh->codec->outfmt[j]; mp_msg(MSGT_CPLAYER, MSGL_V, "VDec: using %s as output csp (no %d)\n", vo_format_name(out_fmt), j); - sh->outfmtidx=j; - sh->vfilter=vf; + sh->outfmtidx = j; + sh->vfilter = vf; // autodetect flipping - if(flip==-1){ - flip=0; - if(sh->codec->outflags[j]&CODECS_FLAG_FLIP) - if(!(sh->codec->outflags[j]&CODECS_FLAG_NOFLIP)) - flip=1; + if (flip == -1) { + flip = 0; + if (sh->codec->outflags[j] & CODECS_FLAG_FLIP) + if (!(sh->codec->outflags[j] & CODECS_FLAG_NOFLIP)) + flip = 1; } - if(vo_flags&VFCAP_FLIPPED) flip^=1; - if(flip && !(vo_flags&VFCAP_FLIP)){ - // we need to flip, but no flipping filter avail. - vf_add_before_vo(&vf, "flip", NULL); - sh->vfilter = vf; + if (vo_flags & VFCAP_FLIPPED) + flip ^= 1; + if (flip && !(vo_flags & VFCAP_FLIP)) { + // we need to flip, but no flipping filter avail. + vf_add_before_vo(&vf, "flip", NULL); + sh->vfilter = vf; } - // time to do aspect ratio corrections... - if(movie_aspect>-1.0) sh->aspect = movie_aspect; // cmdline overrides autodetect - else if(sh->stream_aspect!=0.0) sh->aspect = sh->stream_aspect; + if (movie_aspect > -1.0) + sh->aspect = movie_aspect; // cmdline overrides autodetect + else if (sh->stream_aspect != 0.0) + sh->aspect = sh->stream_aspect; // if(!sh->aspect) sh->aspect=1.0; - if(opt_screen_size_x||opt_screen_size_y){ - screen_size_x = opt_screen_size_x; - screen_size_y = opt_screen_size_y; - if(!vidmode){ - if(!screen_size_x) screen_size_x=SCREEN_SIZE_X; - if(!screen_size_y) screen_size_y=SCREEN_SIZE_Y; - if(screen_size_x<=8) screen_size_x*=sh->disp_w; - if(screen_size_y<=8) screen_size_y*=sh->disp_h; - } - } else { - // check source format aspect, calculate prescale ::atmos - screen_size_x=sh->disp_w; - screen_size_y=sh->disp_h; - if(screen_size_xy>=0.001){ - if(screen_size_xy<=8){ - // -xy means x+y scale - screen_size_x*=screen_size_xy; - screen_size_y*=screen_size_xy; - } else { - // -xy means forced width while keeping correct aspect - screen_size_x=screen_size_xy; - screen_size_y=screen_size_xy*sh->disp_h/sh->disp_w; - } - } - if(sh->aspect>0.01){ - int w; - mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MovieAspectIsSet,sh->aspect); - mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_ASPECT=%1.4f\n", sh->aspect); - w=(int)((float)screen_size_y*sh->aspect); w+=w%2; // round - // we don't like horizontal downscale || user forced width: - if(w8){ - screen_size_y=(int)((float)screen_size_x*(1.0/sh->aspect)); - screen_size_y+=screen_size_y%2; // round - } else screen_size_x=w; // keep new width + if (opt_screen_size_x || opt_screen_size_y) { + screen_size_x = opt_screen_size_x; + screen_size_y = opt_screen_size_y; + if (!vidmode) { + if (!screen_size_x) + screen_size_x = SCREEN_SIZE_X; + if (!screen_size_y) + screen_size_y = SCREEN_SIZE_Y; + if (screen_size_x <= 8) + screen_size_x *= sh->disp_w; + if (screen_size_y <= 8) + screen_size_y *= sh->disp_h; + } } else { - mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MovieAspectUndefined); + // check source format aspect, calculate prescale ::atmos + screen_size_x = sh->disp_w; + screen_size_y = sh->disp_h; + if (screen_size_xy >= 0.001) { + if (screen_size_xy <= 8) { + // -xy means x+y scale + screen_size_x *= screen_size_xy; + screen_size_y *= screen_size_xy; + } else { + // -xy means forced width while keeping correct aspect + screen_size_x = screen_size_xy; + screen_size_y = screen_size_xy * sh->disp_h / sh->disp_w; + } + } + if (sh->aspect > 0.01) { + int w; + mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_MovieAspectIsSet, + sh->aspect); + mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_ASPECT=%1.4f\n", + sh->aspect); + w = (int) ((float) screen_size_y * sh->aspect); + w += w % 2; // round + // we don't like horizontal downscale || user forced width: + if (w < screen_size_x || screen_size_xy > 8) { + screen_size_y = + (int) ((float) screen_size_x * (1.0 / sh->aspect)); + screen_size_y += screen_size_y % 2; // round + } else + screen_size_x = w; // keep new width + } else { + mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_MovieAspectUndefined); + } } - } - vocfg_flags = (fullscreen ? VOFLAG_FULLSCREEN:0) - | (vidmode ? VOFLAG_MODESWITCHING:0) - | (softzoom ? VOFLAG_SWSCALE:0) - | (flip ? VOFLAG_FLIPPING:0); + vocfg_flags = (fullscreen ? VOFLAG_FULLSCREEN : 0) + | (vidmode ? VOFLAG_MODESWITCHING : 0) + | (softzoom ? VOFLAG_SWSCALE : 0) + | (flip ? VOFLAG_FLIPPING : 0); // Time to config libvo! - mp_msg(MSGT_CPLAYER,MSGL_V,"VO Config (%dx%d->%dx%d,flags=%d,'%s',0x%X)\n", - sh->disp_w,sh->disp_h, - screen_size_x,screen_size_y, - vocfg_flags, - "MPlayer",out_fmt); + mp_msg(MSGT_CPLAYER, MSGL_V, + "VO Config (%dx%d->%dx%d,flags=%d,'%s',0x%X)\n", sh->disp_w, + sh->disp_h, screen_size_x, screen_size_y, vocfg_flags, "MPlayer", + out_fmt); vf->w = sh->disp_w; vf->h = sh->disp_h; - if(vf_config_wrapper(vf,sh->disp_w,sh->disp_h, - screen_size_x,screen_size_y, - vocfg_flags, - out_fmt)==0){ + if (vf_config_wrapper + (vf, sh->disp_w, sh->disp_h, screen_size_x, screen_size_y, vocfg_flags, + out_fmt) == 0) { // "MPlayer",out_fmt)){ - mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_CannotInitVO); - sh->vf_initialized=-1; - return 0; + mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_CannotInitVO); + sh->vf_initialized = -1; + return 0; } - sh->vf_initialized=1; + sh->vf_initialized = 1; if (vo_gamma_gamma != 1000) set_video_colors(sh, "gamma", vo_gamma_gamma); @@ -361,15 +387,22 @@ csp_again: // mp_imgflag: buffer requirements (read/write, preserve, stride limits), see mp_image.h // returns NULL or allocated mp_image_t* // Note: buffer allocation may be moved to mpcodecs_config_vo() later... -mp_image_t* mpcodecs_get_image(sh_video_t *sh, int mp_imgtype, int mp_imgflag, int w, int h){ - mp_image_t* mpi=vf_get_image(sh->vfilter,sh->codec->outfmt[sh->outfmtidx],mp_imgtype,mp_imgflag,w,h); - if (mpi) mpi->x=mpi->y=0; - return mpi; +mp_image_t *mpcodecs_get_image(sh_video_t *sh, int mp_imgtype, int mp_imgflag, + int w, int h) +{ + mp_image_t *mpi = + vf_get_image(sh->vfilter, sh->codec->outfmt[sh->outfmtidx], mp_imgtype, + mp_imgflag, w, h); + if (mpi) + mpi->x = mpi->y = 0; + return mpi; } -void mpcodecs_draw_slice(sh_video_t *sh, unsigned char** src, int* stride, int w,int h, int x, int y) { - struct vf_instance *vf = sh->vfilter; +void mpcodecs_draw_slice(sh_video_t *sh, unsigned char **src, int *stride, + int w, int h, int x, int y) +{ + struct vf_instance *vf = sh->vfilter; - if(vf->draw_slice) - vf->draw_slice(vf,src,stride,w,h,x,y); + if (vf->draw_slice) + vf->draw_slice(vf, src, stride, w, h, x, y); } From 4ab8fea71b08b55cf133ba29eeba0a83012957d8 Mon Sep 17 00:00:00 2001 From: diego Date: Thu, 27 May 2010 09:54:37 +0000 Subject: [PATCH 31/55] cosmetics: K&R coding style git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31228 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libmpcodecs/dec_video.c | 569 +++++++++++++++++++++------------------- 1 file changed, 304 insertions(+), 265 deletions(-) diff --git a/libmpcodecs/dec_video.c b/libmpcodecs/dec_video.c index 44fb2b3d22..51da1adf7b 100644 --- a/libmpcodecs/dec_video.c +++ b/libmpcodecs/dec_video.c @@ -53,97 +53,101 @@ extern double vout_time_usage; #include "cpudetect.h" -int field_dominance=-1; +int field_dominance = -1; -int divx_quality=0; +int divx_quality = 0; -const vd_functions_t* mpvdec=NULL; +const vd_functions_t *mpvdec = NULL; -int get_video_quality_max(sh_video_t *sh_video){ - vf_instance_t* vf=sh_video->vfilter; - if(vf){ - int ret=vf->control(vf,VFCTRL_QUERY_MAX_PP_LEVEL,NULL); - if(ret>0){ - mp_msg(MSGT_DECVIDEO,MSGL_INFO,MSGTR_UsingExternalPP,ret); - return ret; - } - } - if(mpvdec){ - int ret=mpvdec->control(sh_video,VDCTRL_QUERY_MAX_PP_LEVEL,NULL); - if(ret>0){ - mp_msg(MSGT_DECVIDEO,MSGL_INFO,MSGTR_UsingCodecPP,ret); - return ret; - } - } -// mp_msg(MSGT_DECVIDEO,MSGL_INFO,"[PP] Sorry, postprocessing is not available\n"); - return 0; -} - -void set_video_quality(sh_video_t *sh_video,int quality){ - vf_instance_t* vf=sh_video->vfilter; - if(vf){ - int ret=vf->control(vf,VFCTRL_SET_PP_LEVEL, (void*)(&quality)); - if(ret==CONTROL_TRUE) return; // success - } - if(mpvdec) - mpvdec->control(sh_video,VDCTRL_SET_PP_LEVEL, (void*)(&quality)); -} - -int set_video_colors(sh_video_t *sh_video,const char *item,int value) +int get_video_quality_max(sh_video_t *sh_video) { - vf_instance_t* vf=sh_video->vfilter; + vf_instance_t *vf = sh_video->vfilter; + if (vf) { + int ret = vf->control(vf, VFCTRL_QUERY_MAX_PP_LEVEL, NULL); + if (ret > 0) { + mp_msg(MSGT_DECVIDEO, MSGL_INFO, MSGTR_UsingExternalPP, ret); + return ret; + } + } + if (mpvdec) { + int ret = mpvdec->control(sh_video, VDCTRL_QUERY_MAX_PP_LEVEL, NULL); + if (ret > 0) { + mp_msg(MSGT_DECVIDEO, MSGL_INFO, MSGTR_UsingCodecPP, ret); + return ret; + } + } +// mp_msg(MSGT_DECVIDEO,MSGL_INFO,"[PP] Sorry, postprocessing is not available\n"); + return 0; +} + +void set_video_quality(sh_video_t *sh_video, int quality) +{ + vf_instance_t *vf = sh_video->vfilter; + if (vf) { + int ret = vf->control(vf, VFCTRL_SET_PP_LEVEL, (void *) (&quality)); + if (ret == CONTROL_TRUE) + return; // success + } + if (mpvdec) + mpvdec->control(sh_video, VDCTRL_SET_PP_LEVEL, (void *) (&quality)); +} + +int set_video_colors(sh_video_t *sh_video, const char *item, int value) +{ + vf_instance_t *vf = sh_video->vfilter; vf_equalizer_t data; data.item = item; data.value = value; - mp_dbg(MSGT_DECVIDEO,MSGL_V,"set video colors %s=%d \n", item, value); - if (vf) - { - int ret = vf->control(vf, VFCTRL_SET_EQUALIZER, &data); - if (ret == CONTROL_TRUE) - return 1; + mp_dbg(MSGT_DECVIDEO, MSGL_V, "set video colors %s=%d \n", item, value); + if (vf) { + int ret = vf->control(vf, VFCTRL_SET_EQUALIZER, &data); + if (ret == CONTROL_TRUE) + return 1; } /* try software control */ - if(mpvdec) - if( mpvdec->control(sh_video,VDCTRL_SET_EQUALIZER, item, (int *)value) - == CONTROL_OK) return 1; - mp_msg(MSGT_DECVIDEO,MSGL_V,MSGTR_VideoAttributeNotSupportedByVO_VD,item); + if (mpvdec) + if (mpvdec->control + (sh_video, VDCTRL_SET_EQUALIZER, item, (int *) value) + == CONTROL_OK) + return 1; + mp_msg(MSGT_DECVIDEO, MSGL_V, MSGTR_VideoAttributeNotSupportedByVO_VD, + item); return 0; } -int get_video_colors(sh_video_t *sh_video,const char *item,int *value) +int get_video_colors(sh_video_t *sh_video, const char *item, int *value) { - vf_instance_t* vf=sh_video->vfilter; + vf_instance_t *vf = sh_video->vfilter; vf_equalizer_t data; data.item = item; - mp_dbg(MSGT_DECVIDEO,MSGL_V,"get video colors %s \n", item); - if (vf) - { + mp_dbg(MSGT_DECVIDEO, MSGL_V, "get video colors %s \n", item); + if (vf) { int ret = vf->control(vf, VFCTRL_GET_EQUALIZER, &data); - if (ret == CONTROL_TRUE){ - *value = data.value; - return 1; - } + if (ret == CONTROL_TRUE) { + *value = data.value; + return 1; + } } /* try software control */ - if(mpvdec) return mpvdec->control(sh_video,VDCTRL_GET_EQUALIZER, item, value); + if (mpvdec) + return mpvdec->control(sh_video, VDCTRL_GET_EQUALIZER, item, value); return 0; } -int set_rectangle(sh_video_t *sh_video,int param,int value) +int set_rectangle(sh_video_t *sh_video, int param, int value) { - vf_instance_t* vf=sh_video->vfilter; - int data[] = {param, value}; + vf_instance_t *vf = sh_video->vfilter; + int data[] = { param, value }; - mp_dbg(MSGT_DECVIDEO,MSGL_V,"set rectangle \n"); - if (vf) - { + mp_dbg(MSGT_DECVIDEO, MSGL_V, "set rectangle \n"); + if (vf) { int ret = vf->control(vf, VFCTRL_CHANGE_RECTANGLE, data); - if (ret) - return 1; + if (ret) + return 1; } return 0; } @@ -154,7 +158,8 @@ void resync_video_stream(sh_video_t *sh_video) sh_video->next_frame_time = 0; sh_video->num_buffered_pts = 0; sh_video->last_pts = MP_NOPTS_VALUE; - if(mpvdec) mpvdec->control(sh_video, VDCTRL_RESYNC_STREAM, NULL); + if (mpvdec) + mpvdec->control(sh_video, VDCTRL_RESYNC_STREAM, NULL); } int get_current_video_decoder_lag(sh_video_t *sh_video) @@ -162,191 +167,226 @@ int get_current_video_decoder_lag(sh_video_t *sh_video) int ret; if (!mpvdec) - return -1; + return -1; ret = mpvdec->control(sh_video, VDCTRL_QUERY_UNSEEN_FRAMES, NULL); if (ret >= 10) - return ret-10; + return ret - 10; return -1; } -void uninit_video(sh_video_t *sh_video){ - if(!sh_video->initialized) return; - mp_msg(MSGT_DECVIDEO,MSGL_V,MSGTR_UninitVideoStr,sh_video->codec->drv); +void uninit_video(sh_video_t *sh_video) +{ + if (!sh_video->initialized) + return; + mp_msg(MSGT_DECVIDEO, MSGL_V, MSGTR_UninitVideoStr, sh_video->codec->drv); mpvdec->uninit(sh_video); #ifdef CONFIG_DYNAMIC_PLUGINS if (sh_video->dec_handle) - dlclose(sh_video->dec_handle); + dlclose(sh_video->dec_handle); #endif vf_uninit_filter_chain(sh_video->vfilter); - sh_video->initialized=0; + sh_video->initialized = 0; } -void vfm_help(void){ +void vfm_help(void) +{ int i; - mp_msg(MSGT_DECVIDEO,MSGL_INFO,MSGTR_AvailableVideoFm); + mp_msg(MSGT_DECVIDEO, MSGL_INFO, MSGTR_AvailableVideoFm); mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_DRIVERS\n"); - mp_msg(MSGT_DECVIDEO,MSGL_INFO," vfm: info: (comment)\n"); - for (i=0; mpcodecs_vd_drivers[i] != NULL; i++) - mp_msg(MSGT_DECVIDEO,MSGL_INFO,"%8s %s (%s)\n", - mpcodecs_vd_drivers[i]->info->short_name, - mpcodecs_vd_drivers[i]->info->name, - mpcodecs_vd_drivers[i]->info->comment); + mp_msg(MSGT_DECVIDEO, MSGL_INFO, " vfm: info: (comment)\n"); + for (i = 0; mpcodecs_vd_drivers[i] != NULL; i++) + mp_msg(MSGT_DECVIDEO, MSGL_INFO, "%8s %s (%s)\n", + mpcodecs_vd_drivers[i]->info->short_name, + mpcodecs_vd_drivers[i]->info->name, + mpcodecs_vd_drivers[i]->info->comment); } -static int init_video(sh_video_t *sh_video,char* codecname,char* vfm,int status, - stringset_t *selected){ +static int init_video(sh_video_t *sh_video, char *codecname, char *vfm, + int status, stringset_t *selected) +{ int force = 0; - unsigned int orig_fourcc=sh_video->bih?sh_video->bih->biCompression:0; - sh_video->codec=NULL; - sh_video->vf_initialized=0; + unsigned int orig_fourcc = + sh_video->bih ? sh_video->bih->biCompression : 0; + sh_video->codec = NULL; + sh_video->vf_initialized = 0; if (codecname && codecname[0] == '+') { - codecname = &codecname[1]; - force = 1; + codecname = &codecname[1]; + force = 1; } - while(1){ - int i; - int orig_w, orig_h; - // restore original fourcc: - if(sh_video->bih) sh_video->bih->biCompression=orig_fourcc; - if(!(sh_video->codec=find_video_codec(sh_video->format, - sh_video->bih?((unsigned int*) &sh_video->bih->biCompression):NULL, - sh_video->codec,force) )) break; - // ok we found one codec - if(stringset_test(selected, sh_video->codec->name)) continue; // already tried & failed - if(codecname && strcmp(sh_video->codec->name,codecname)) continue; // -vc - if(vfm && strcmp(sh_video->codec->drv,vfm)) continue; // vfm doesn't match - if(!force && sh_video->codec->statuscodec->name); // tagging it - // ok, it matches all rules, let's find the driver! - for (i=0; mpcodecs_vd_drivers[i] != NULL; i++) -// if(mpcodecs_vd_drivers[i]->info->id==sh_video->codec->driver) break; - if(!strcmp(mpcodecs_vd_drivers[i]->info->short_name,sh_video->codec->drv)) break; - mpvdec=mpcodecs_vd_drivers[i]; + while (1) { + int i; + int orig_w, orig_h; + // restore original fourcc: + if (sh_video->bih) + sh_video->bih->biCompression = orig_fourcc; + if (! + (sh_video->codec = + find_video_codec(sh_video->format, + sh_video-> + bih ? ((unsigned int *) &sh_video->bih-> + biCompression) : NULL, sh_video->codec, + force))) + break; + // ok we found one codec + if (stringset_test(selected, sh_video->codec->name)) + continue; // already tried & failed + if (codecname && strcmp(sh_video->codec->name, codecname)) + continue; // -vc + if (vfm && strcmp(sh_video->codec->drv, vfm)) + continue; // vfm doesn't match + if (!force && sh_video->codec->status < status) + continue; // too unstable + stringset_add(selected, sh_video->codec->name); // tagging it + // ok, it matches all rules, let's find the driver! + for (i = 0; mpcodecs_vd_drivers[i] != NULL; i++) +// if(mpcodecs_vd_drivers[i]->info->id==sh_video->codec->driver) break; + if (!strcmp + (mpcodecs_vd_drivers[i]->info->short_name, + sh_video->codec->drv)) + break; + mpvdec = mpcodecs_vd_drivers[i]; #ifdef CONFIG_DYNAMIC_PLUGINS - if (!mpvdec) - { - /* try to open shared decoder plugin */ - int buf_len; - char *buf; - vd_functions_t *funcs_sym; - vd_info_t *info_sym; + if (!mpvdec) { + /* try to open shared decoder plugin */ + int buf_len; + char *buf; + vd_functions_t *funcs_sym; + vd_info_t *info_sym; - buf_len = strlen(MPLAYER_LIBDIR)+strlen(sh_video->codec->drv)+16; - buf = malloc(buf_len); - if (!buf) - break; - snprintf(buf, buf_len, "%s/mplayer/vd_%s.so", MPLAYER_LIBDIR, sh_video->codec->drv); - mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "Trying to open external plugin: %s\n", buf); - sh_video->dec_handle = dlopen(buf, RTLD_LAZY); - if (!sh_video->dec_handle) - break; - snprintf(buf, buf_len, "mpcodecs_vd_%s", sh_video->codec->drv); - funcs_sym = dlsym(sh_video->dec_handle, buf); - if (!funcs_sym || !funcs_sym->info || !funcs_sym->init || - !funcs_sym->uninit || !funcs_sym->control || !funcs_sym->decode) - break; - info_sym = funcs_sym->info; - if (strcmp(info_sym->short_name, sh_video->codec->drv)) - break; - free(buf); - mpvdec = funcs_sym; - mp_msg(MSGT_DECVIDEO, MSGL_V, "Using external decoder plugin (%s/mplayer/vd_%s.so)!\n", - MPLAYER_LIBDIR, sh_video->codec->drv); - } + buf_len = + strlen(MPLAYER_LIBDIR) + strlen(sh_video->codec->drv) + 16; + buf = malloc(buf_len); + if (!buf) + break; + snprintf(buf, buf_len, "%s/mplayer/vd_%s.so", MPLAYER_LIBDIR, + sh_video->codec->drv); + mp_msg(MSGT_DECVIDEO, MSGL_DBG2, + "Trying to open external plugin: %s\n", buf); + sh_video->dec_handle = dlopen(buf, RTLD_LAZY); + if (!sh_video->dec_handle) + break; + snprintf(buf, buf_len, "mpcodecs_vd_%s", sh_video->codec->drv); + funcs_sym = dlsym(sh_video->dec_handle, buf); + if (!funcs_sym || !funcs_sym->info || !funcs_sym->init + || !funcs_sym->uninit || !funcs_sym->control + || !funcs_sym->decode) + break; + info_sym = funcs_sym->info; + if (strcmp(info_sym->short_name, sh_video->codec->drv)) + break; + free(buf); + mpvdec = funcs_sym; + mp_msg(MSGT_DECVIDEO, MSGL_V, + "Using external decoder plugin (%s/mplayer/vd_%s.so)!\n", + MPLAYER_LIBDIR, sh_video->codec->drv); + } #endif - if(!mpvdec){ // driver not available (==compiled in) - mp_msg(MSGT_DECVIDEO,MSGL_WARN,MSGTR_VideoCodecFamilyNotAvailableStr, - sh_video->codec->name, sh_video->codec->drv); - continue; - } - orig_w = sh_video->bih ? sh_video->bih->biWidth : sh_video->disp_w; - orig_h = sh_video->bih ? sh_video->bih->biHeight : sh_video->disp_h; - sh_video->disp_w = orig_w; - sh_video->disp_h = orig_h; - // it's available, let's try to init! - if(sh_video->codec->flags & CODECS_FLAG_ALIGN16){ - // align width/height to n*16 - sh_video->disp_w=(sh_video->disp_w+15)&(~15); - sh_video->disp_h=(sh_video->disp_h+15)&(~15); - } - if (sh_video->bih) { - sh_video->bih->biWidth = sh_video->disp_w; - sh_video->bih->biHeight = sh_video->disp_h; - } - // init() - mp_msg(MSGT_DECVIDEO,MSGL_INFO,MSGTR_OpeningVideoDecoder,mpvdec->info->short_name,mpvdec->info->name); - // clear vf init error, it is no longer relevant - if (sh_video->vf_initialized < 0) - sh_video->vf_initialized = 0; - if(!mpvdec->init(sh_video)){ - mp_msg(MSGT_DECVIDEO,MSGL_INFO,MSGTR_VDecoderInitFailed); - sh_video->disp_w=orig_w; - sh_video->disp_h=orig_h; - if (sh_video->bih) { - sh_video->bih->biWidth = sh_video->disp_w; - sh_video->bih->biHeight = sh_video->disp_h; - } - continue; // try next... - } - // Yeah! We got it! - sh_video->initialized=1; - return 1; + if (!mpvdec) { // driver not available (==compiled in) + mp_msg(MSGT_DECVIDEO, MSGL_WARN, + MSGTR_VideoCodecFamilyNotAvailableStr, + sh_video->codec->name, sh_video->codec->drv); + continue; + } + orig_w = sh_video->bih ? sh_video->bih->biWidth : sh_video->disp_w; + orig_h = sh_video->bih ? sh_video->bih->biHeight : sh_video->disp_h; + sh_video->disp_w = orig_w; + sh_video->disp_h = orig_h; + // it's available, let's try to init! + if (sh_video->codec->flags & CODECS_FLAG_ALIGN16) { + // align width/height to n*16 + sh_video->disp_w = (sh_video->disp_w + 15) & (~15); + sh_video->disp_h = (sh_video->disp_h + 15) & (~15); + } + if (sh_video->bih) { + sh_video->bih->biWidth = sh_video->disp_w; + sh_video->bih->biHeight = sh_video->disp_h; + } + // init() + mp_msg(MSGT_DECVIDEO, MSGL_INFO, MSGTR_OpeningVideoDecoder, + mpvdec->info->short_name, mpvdec->info->name); + // clear vf init error, it is no longer relevant + if (sh_video->vf_initialized < 0) + sh_video->vf_initialized = 0; + if (!mpvdec->init(sh_video)) { + mp_msg(MSGT_DECVIDEO, MSGL_INFO, MSGTR_VDecoderInitFailed); + sh_video->disp_w = orig_w; + sh_video->disp_h = orig_h; + if (sh_video->bih) { + sh_video->bih->biWidth = sh_video->disp_w; + sh_video->bih->biHeight = sh_video->disp_h; + } + continue; // try next... + } + // Yeah! We got it! + sh_video->initialized = 1; + return 1; } return 0; } -int init_best_video_codec(sh_video_t *sh_video,char** video_codec_list,char** video_fm_list){ -char* vc_l_default[2]={"",(char*)NULL}; -stringset_t selected; -// hack: -if(!video_codec_list) video_codec_list=vc_l_default; -// Go through the codec.conf and find the best codec... -sh_video->initialized=0; -stringset_init(&selected); -while(!sh_video->initialized && *video_codec_list){ - char* video_codec=*(video_codec_list++); - if(video_codec[0]){ - if(video_codec[0]=='-'){ - // disable this codec: - stringset_add(&selected, video_codec+1); - } else { - // forced codec by name: - mp_msg(MSGT_DECVIDEO,MSGL_INFO,MSGTR_ForcedVideoCodec,video_codec); - init_video(sh_video,video_codec,NULL,-1, &selected); +int init_best_video_codec(sh_video_t *sh_video, char **video_codec_list, + char **video_fm_list) +{ + char *vc_l_default[2] = { "", (char *) NULL }; + stringset_t selected; + // hack: + if (!video_codec_list) + video_codec_list = vc_l_default; + // Go through the codec.conf and find the best codec... + sh_video->initialized = 0; + stringset_init(&selected); + while (!sh_video->initialized && *video_codec_list) { + char *video_codec = *(video_codec_list++); + if (video_codec[0]) { + if (video_codec[0] == '-') { + // disable this codec: + stringset_add(&selected, video_codec + 1); + } else { + // forced codec by name: + mp_msg(MSGT_DECVIDEO, MSGL_INFO, MSGTR_ForcedVideoCodec, + video_codec); + init_video(sh_video, video_codec, NULL, -1, &selected); + } + } else { + int status; + // try in stability order: UNTESTED, WORKING, BUGGY. never try CRASHING. + if (video_fm_list) { + char **fmlist = video_fm_list; + // try first the preferred codec families: + while (!sh_video->initialized && *fmlist) { + char *video_fm = *(fmlist++); + mp_msg(MSGT_DECVIDEO, MSGL_INFO, MSGTR_TryForceVideoFmtStr, + video_fm); + for (status = CODECS_STATUS__MAX; + status >= CODECS_STATUS__MIN; --status) + if (init_video + (sh_video, NULL, video_fm, status, &selected)) + break; + } + } + if (!sh_video->initialized) + for (status = CODECS_STATUS__MAX; status >= CODECS_STATUS__MIN; + --status) + if (init_video(sh_video, NULL, NULL, status, &selected)) + break; + } } - } else { - int status; - // try in stability order: UNTESTED, WORKING, BUGGY. never try CRASHING. - if(video_fm_list){ - char** fmlist=video_fm_list; - // try first the preferred codec families: - while(!sh_video->initialized && *fmlist){ - char* video_fm=*(fmlist++); - mp_msg(MSGT_DECVIDEO,MSGL_INFO,MSGTR_TryForceVideoFmtStr,video_fm); - for(status=CODECS_STATUS__MAX;status>=CODECS_STATUS__MIN;--status) - if(init_video(sh_video,NULL,video_fm,status, &selected)) break; - } + stringset_free(&selected); + + if (!sh_video->initialized) { + mp_msg(MSGT_DECVIDEO, MSGL_ERR, MSGTR_CantFindVideoCodec, + sh_video->format); + return 0; // failed } - if(!sh_video->initialized) - for(status=CODECS_STATUS__MAX;status>=CODECS_STATUS__MIN;--status) - if(init_video(sh_video,NULL,NULL,status, &selected)) break; - } -} -stringset_free(&selected); -if(!sh_video->initialized){ - mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_CantFindVideoCodec,sh_video->format); - return 0; // failed -} - -mp_msg(MSGT_DECVIDEO,MSGL_INFO,MSGTR_SelectedVideoCodec, - sh_video->codec->name,sh_video->codec->drv,sh_video->codec->info); -return 1; // success + mp_msg(MSGT_DECVIDEO, MSGL_INFO, MSGTR_SelectedVideoCodec, + sh_video->codec->name, sh_video->codec->drv, sh_video->codec->info); + return 1; // success } void *decode_video(sh_video_t *sh_video, unsigned char *start, int in_size, - int drop_frame, double pts) + int drop_frame, double pts) { mp_image_t *mpi = NULL; unsigned int t = GetTimer(); @@ -354,33 +394,33 @@ void *decode_video(sh_video_t *sh_video, unsigned char *start, int in_size, double tt; if (correct_pts && pts != MP_NOPTS_VALUE) { - int delay = get_current_video_decoder_lag(sh_video); - if (delay >= 0) { - if (delay > sh_video->num_buffered_pts) + int delay = get_current_video_decoder_lag(sh_video); + if (delay >= 0) { + if (delay > sh_video->num_buffered_pts) #if 0 - // this is disabled because vd_ffmpeg reports the same lag - // after seek even when there are no buffered frames, - // leading to incorrect error messages - mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Not enough buffered pts\n"); + // this is disabled because vd_ffmpeg reports the same lag + // after seek even when there are no buffered frames, + // leading to incorrect error messages + mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Not enough buffered pts\n"); #else - ; + ; #endif - else - sh_video->num_buffered_pts = delay; - } - if (sh_video->num_buffered_pts == - sizeof(sh_video->buffered_pts)/sizeof(double)) - mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Too many buffered pts\n"); - else { - int i, j; - for (i = 0; i < sh_video->num_buffered_pts; i++) - if (sh_video->buffered_pts[i] < pts) - break; - for (j = sh_video->num_buffered_pts; j > i; j--) - sh_video->buffered_pts[j] = sh_video->buffered_pts[j-1]; - sh_video->buffered_pts[i] = pts; - sh_video->num_buffered_pts++; - } + else + sh_video->num_buffered_pts = delay; + } + if (sh_video->num_buffered_pts == + sizeof(sh_video->buffered_pts) / sizeof(double)) + mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Too many buffered pts\n"); + else { + int i, j; + for (i = 0; i < sh_video->num_buffered_pts; i++) + if (sh_video->buffered_pts[i] < pts) + break; + for (j = sh_video->num_buffered_pts; j > i; j--) + sh_video->buffered_pts[j] = sh_video->buffered_pts[j - 1]; + sh_video->buffered_pts[i] = pts; + sh_video->num_buffered_pts++; + } } mpi = mpvdec->decode(sh_video, start, in_size, drop_frame); @@ -391,35 +431,34 @@ void *decode_video(sh_video_t *sh_video, unsigned char *start, int in_size, // some codecs are broken, and doesn't restore MMX state :( // it happens usually with broken/damaged files. if (gCpuCaps.has3DNow) { - __asm__ volatile ("femms\n\t":::"memory"); - } - else if (gCpuCaps.hasMMX) { - __asm__ volatile ("emms\n\t":::"memory"); + __asm__ volatile ("femms\n\t":::"memory"); + } else if (gCpuCaps.hasMMX) { + __asm__ volatile ("emms\n\t":::"memory"); } #endif - t2 = GetTimer(); t = t2-t; - tt = t*0.000001f; + t2 = GetTimer(); + t = t2 - t; + tt = t * 0.000001f; video_time_usage += tt; if (!mpi || drop_frame) - return NULL; // error / skipped frame + return NULL; // error / skipped frame if (field_dominance == 0) - mpi->fields |= MP_IMGFIELD_TOP_FIRST; + mpi->fields |= MP_IMGFIELD_TOP_FIRST; else if (field_dominance == 1) - mpi->fields &= ~MP_IMGFIELD_TOP_FIRST; + mpi->fields &= ~MP_IMGFIELD_TOP_FIRST; if (correct_pts) { - if (sh_video->num_buffered_pts) { - sh_video->num_buffered_pts--; - sh_video->pts = sh_video->buffered_pts[sh_video->num_buffered_pts]; - } - else { - mp_msg(MSGT_CPLAYER, MSGL_ERR, "No pts value from demuxer to " - "use for frame!\n"); - sh_video->pts = MP_NOPTS_VALUE; - } + if (sh_video->num_buffered_pts) { + sh_video->num_buffered_pts--; + sh_video->pts = sh_video->buffered_pts[sh_video->num_buffered_pts]; + } else { + mp_msg(MSGT_CPLAYER, MSGL_ERR, + "No pts value from demuxer to " "use for frame!\n"); + sh_video->pts = MP_NOPTS_VALUE; + } } return mpi; } @@ -432,17 +471,17 @@ int filter_video(sh_video_t *sh_video, void *frame, double pts) // apply video filters and call the leaf vo/ve int ret = vf->put_image(vf, mpi, pts); if (ret > 0) { - // draw EOSD first so it ends up below the OSD. - // Note that changing this is will not work right with vf_ass and the - // vos currently always draw the EOSD first in paused mode. + // draw EOSD first so it ends up below the OSD. + // Note that changing this is will not work right with vf_ass and the + // vos currently always draw the EOSD first in paused mode. #ifdef CONFIG_ASS - vf->control(vf, VFCTRL_DRAW_EOSD, NULL); + vf->control(vf, VFCTRL_DRAW_EOSD, NULL); #endif - vf->control(vf, VFCTRL_DRAW_OSD, NULL); + vf->control(vf, VFCTRL_DRAW_OSD, NULL); } - t2 = GetTimer()-t2; - vout_time_usage += t2*0.000001; + t2 = GetTimer() - t2; + vout_time_usage += t2 * 0.000001; return ret; } From 67958c9b9ff7a3130d175581ef27caa308d15ae8 Mon Sep 17 00:00:00 2001 From: diego Date: Thu, 27 May 2010 09:59:15 +0000 Subject: [PATCH 32/55] cosmetics: Drop _s suffix from 'struct vd_functions'. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31229 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libmpcodecs/vd.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libmpcodecs/vd.h b/libmpcodecs/vd.h index 6c9593dd0a..30b10ce651 100644 --- a/libmpcodecs/vd.h +++ b/libmpcodecs/vd.h @@ -26,7 +26,7 @@ typedef mp_codec_info_t vd_info_t; /* interface of video decoder drivers */ -typedef struct vd_functions_s +typedef struct vd_functions { const vd_info_t *info; int (*init)(sh_video_t *sh); From 9bc124bcdafbb5c8a55e7e4d25c8faade9869931 Mon Sep 17 00:00:00 2001 From: diego Date: Thu, 27 May 2010 10:08:30 +0000 Subject: [PATCH 33/55] cosmetics: Drop pointless _s suffix from 'struct mp_image'. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31230 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libmpcodecs/mp_image.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libmpcodecs/mp_image.h b/libmpcodecs/mp_image.h index 334b3c986d..dd69788f26 100644 --- a/libmpcodecs/mp_image.h +++ b/libmpcodecs/mp_image.h @@ -96,7 +96,7 @@ #define MP_IMGFIELD_BOTTOM 0x10 #define MP_IMGFIELD_INTERLACED 0x20 -typedef struct mp_image_s { +typedef struct mp_image { unsigned int flags; unsigned char type; int number; From b17704e6a86d5710cb86b150290886b2c3a06afd Mon Sep 17 00:00:00 2001 From: diego Date: Thu, 27 May 2010 10:10:27 +0000 Subject: [PATCH 34/55] cosmetics: Drop pointless _s suffix from 'struct ad_functions'. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31231 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libmpcodecs/ad.h | 2 +- libmpdemux/stheader.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libmpcodecs/ad.h b/libmpcodecs/ad.h index 1fa94d2e9e..9b1daf9e48 100644 --- a/libmpcodecs/ad.h +++ b/libmpcodecs/ad.h @@ -25,7 +25,7 @@ typedef mp_codec_info_t ad_info_t; /* interface of video decoder drivers */ -typedef struct ad_functions_s +typedef struct ad_functions { const ad_info_t *info; int (*preinit)(sh_audio_t *sh); diff --git a/libmpdemux/stheader.h b/libmpdemux/stheader.h index c8624aea3e..d7adc6478b 100644 --- a/libmpdemux/stheader.h +++ b/libmpdemux/stheader.h @@ -73,7 +73,7 @@ typedef struct sh_audio { int a_out_buffer_size; // void* audio_out; // the audio_out handle, used for this audio stream struct af_stream_s *afilter; // the audio filter stream - struct ad_functions_s* ad_driver; + struct ad_functions *ad_driver; #ifdef CONFIG_DYNAMIC_PLUGINS void *dec_handle; #endif From 8350f5430adeae03cb4d46b8acee647252ea8594 Mon Sep 17 00:00:00 2001 From: diego Date: Thu, 27 May 2010 16:05:30 +0000 Subject: [PATCH 35/55] Remove unnecessary demux_mkv_seek() forward declaration. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31232 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libmpdemux/demux_mkv.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/libmpdemux/demux_mkv.c b/libmpdemux/demux_mkv.c index ecb171c551..73460f735f 100644 --- a/libmpdemux/demux_mkv.c +++ b/libmpdemux/demux_mkv.c @@ -2040,8 +2040,6 @@ demux_mkv_open_sub (demuxer_t *demuxer, mkv_track_t *track, int sid) return 0; } -static void demux_mkv_seek (demuxer_t *demuxer, float rel_seek_secs, float audio_delay, int flags); - static int demux_mkv_open (demuxer_t *demuxer) { From 16a226da45740983fae38d4f99a778c8048b8afe Mon Sep 17 00:00:00 2001 From: diego Date: Thu, 27 May 2010 16:13:53 +0000 Subject: [PATCH 36/55] Remove two pointless void* casts. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31233 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libmpdemux/demux_mkv.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libmpdemux/demux_mkv.c b/libmpdemux/demux_mkv.c index 73460f735f..fbae060005 100644 --- a/libmpdemux/demux_mkv.c +++ b/libmpdemux/demux_mkv.c @@ -1963,14 +1963,13 @@ demux_mkv_open_audio (demuxer_t *demuxer, mkv_track_t *track, int aid) if (track->a_formattag == mmioFOURCC('f', 'L', 'a', 'C')) { - ptr = (unsigned char *)track->private_data; + ptr = track->private_data; size = track->private_size; } else { sh_a->format = mmioFOURCC('f', 'L', 'a', 'C'); - ptr = (unsigned char *) track->private_data - + sizeof (WAVEFORMATEX); + ptr = track->private_data + sizeof (WAVEFORMATEX); size = track->private_size - sizeof (WAVEFORMATEX); } if (size < 4 || ptr[0] != 'f' || ptr[1] != 'L' || From 52b364075b04e25af8ac2e1dfd461aaef5646054 Mon Sep 17 00:00:00 2001 From: diego Date: Thu, 27 May 2010 16:46:47 +0000 Subject: [PATCH 37/55] cosmetics: Reformat in K&R coding style. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31234 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libmpdemux/demux_mkv.c | 4591 +++++++++++++++++++--------------------- libmpdemux/ebml.c | 384 ++-- 2 files changed, 2393 insertions(+), 2582 deletions(-) diff --git a/libmpdemux/demux_mkv.c b/libmpdemux/demux_mkv.c index fbae060005..2f8edb396e 100644 --- a/libmpdemux/demux_mkv.c +++ b/libmpdemux/demux_mkv.c @@ -58,138 +58,136 @@ #include "libavutil/intreadwrite.h" #include "libavutil/avstring.h" -static const unsigned char sipr_swaps[38][2]={ +static const unsigned char sipr_swaps[38][2] = { {0,63},{1,22},{2,44},{3,90},{5,81},{7,31},{8,86},{9,58},{10,36},{12,68}, {13,39},{14,73},{15,53},{16,69},{17,57},{19,88},{20,34},{21,71},{24,46}, {25,94},{26,54},{28,75},{29,50},{32,70},{33,92},{35,74},{38,85},{40,56}, {42,87},{43,65},{45,59},{48,79},{49,93},{51,89},{55,95},{61,76},{67,83}, - {77,80} }; + {77,80} +}; // Map flavour to bytes per second #define SIPR_FLAVORS 4 #define ATRC_FLAVORS 8 #define COOK_FLAVORS 34 -static const int sipr_fl2bps[SIPR_FLAVORS] = {813, 1062, 625, 2000}; -static const int atrc_fl2bps[ATRC_FLAVORS] = - {8269, 11714, 13092, 16538, 18260, 22050, 33075, 44100}; -static const int cook_fl2bps[COOK_FLAVORS] = - { 1000, 1378, 2024, 2584, 4005, 5513, 8010, 4005, 750, 2498, - 4048, 5513, 8010, 11973, 8010, 2584, 4005, 2067, 2584, 2584, - 4005, 4005, 5513, 5513, 8010, 12059, 1550, 8010, 12059, 5513, - 12016, 16408, 22911, 33506}; +static const int sipr_fl2bps[SIPR_FLAVORS] = { 813, 1062, 625, 2000 }; +static const int atrc_fl2bps[ATRC_FLAVORS] = { + 8269, 11714, 13092, 16538, 18260, 22050, 33075, 44100 }; +static const int cook_fl2bps[COOK_FLAVORS] = { + 1000, 1378, 2024, 2584, 4005, 5513, 8010, 4005, 750, 2498, + 4048, 5513, 8010, 11973, 8010, 2584, 4005, 2067, 2584, 2584, + 4005, 4005, 5513, 5513, 8010, 12059, 1550, 8010, 12059, 5513, + 12016, 16408, 22911, 33506 +}; -typedef struct -{ - uint32_t order, type, scope; - uint32_t comp_algo; - uint8_t *comp_settings; - int comp_settings_len; +typedef struct { + uint32_t order, type, scope; + uint32_t comp_algo; + uint8_t *comp_settings; + int comp_settings_len; } mkv_content_encoding_t; -typedef struct mkv_track -{ - int tnum; - char *name; +typedef struct mkv_track { + int tnum; + char *name; - char *codec_id; - int ms_compat; - char *language; + char *codec_id; + int ms_compat; + char *language; - int type; + int type; - uint32_t v_width, v_height, v_dwidth, v_dheight; - float v_frate; + uint32_t v_width, v_height, v_dwidth, v_dheight; + float v_frate; - uint32_t a_formattag; - uint32_t a_channels, a_bps; - float a_sfreq; + uint32_t a_formattag; + uint32_t a_channels, a_bps; + float a_sfreq; - float default_duration; + float default_duration; - int default_track; + int default_track; - void *private_data; - unsigned int private_size; + void *private_data; + unsigned int private_size; - /* stuff for realmedia */ - int realmedia; - int64_t rv_kf_base; - int rv_kf_pts; - float rv_pts; /* previous video timestamp */ - float ra_pts; /* previous audio timestamp */ + /* stuff for realmedia */ + int realmedia; + int64_t rv_kf_base; + int rv_kf_pts; + float rv_pts; /* previous video timestamp */ + float ra_pts; /* previous audio timestamp */ - /** realaudio descrambling */ - int sub_packet_size; ///< sub packet size, per stream - int sub_packet_h; ///< number of coded frames per block - int coded_framesize; ///< coded frame size, per stream - int audiopk_size; ///< audio packet size - unsigned char *audio_buf; ///< place to store reordered audio data - float *audio_timestamp; ///< timestamp for each audio packet - int sub_packet_cnt; ///< number of subpacket already received - int audio_filepos; ///< file position of first audio packet in block + /** realaudio descrambling */ + int sub_packet_size; ///< sub packet size, per stream + int sub_packet_h; ///< number of coded frames per block + int coded_framesize; ///< coded frame size, per stream + int audiopk_size; ///< audio packet size + unsigned char *audio_buf; ///< place to store reordered audio data + float *audio_timestamp; ///< timestamp for each audio packet + int sub_packet_cnt; ///< number of subpacket already received + int audio_filepos; ///< file position of first audio packet in block - /* stuff for quicktime */ - int fix_i_bps; - float qt_last_a_pts; + /* stuff for quicktime */ + int fix_i_bps; + float qt_last_a_pts; - int subtitle_type; + int subtitle_type; - /* The timecodes of video frames might have to be reordered if they're - in display order (the timecodes, not the frames themselves!). In this - case demux packets have to be cached with the help of these variables. */ - int reorder_timecodes; - demux_packet_t **cached_dps; - int num_cached_dps, num_allocated_dps; - float max_pts; + /* The timecodes of video frames might have to be reordered if they're + in display order (the timecodes, not the frames themselves!). In this + case demux packets have to be cached with the help of these variables. */ + int reorder_timecodes; + demux_packet_t **cached_dps; + int num_cached_dps, num_allocated_dps; + float max_pts; - /* generic content encoding support */ - mkv_content_encoding_t *encodings; - int num_encodings; + /* generic content encoding support */ + mkv_content_encoding_t *encodings; + int num_encodings; - /* For VobSubs and SSA/ASS */ - sh_sub_t *sh_sub; + /* For VobSubs and SSA/ASS */ + sh_sub_t *sh_sub; } mkv_track_t; -typedef struct mkv_index -{ - int tnum; - uint64_t timecode, filepos; +typedef struct mkv_index { + int tnum; + uint64_t timecode, filepos; } mkv_index_t; -typedef struct mkv_demuxer -{ - off_t segment_start; +typedef struct mkv_demuxer { + off_t segment_start; - float duration, last_pts; - uint64_t last_filepos; + float duration, last_pts; + uint64_t last_filepos; - mkv_track_t **tracks; - int num_tracks; + mkv_track_t **tracks; + int num_tracks; - uint64_t tc_scale, cluster_tc, first_tc; - int has_first_tc; + uint64_t tc_scale, cluster_tc, first_tc; + int has_first_tc; - uint64_t cluster_size; - uint64_t blockgroup_size; + uint64_t cluster_size; + uint64_t blockgroup_size; - mkv_index_t *indexes; - int num_indexes; + mkv_index_t *indexes; + int num_indexes; - off_t *parsed_cues; - int parsed_cues_num; - off_t *parsed_seekhead; - int parsed_seekhead_num; + off_t *parsed_cues; + int parsed_cues_num; + off_t *parsed_seekhead; + int parsed_seekhead_num; - uint64_t *cluster_positions; - int num_cluster_pos; + uint64_t *cluster_positions; + int num_cluster_pos; - int64_t skip_to_timecode; - int v_skip_to_keyframe, a_skip_to_keyframe; + int64_t skip_to_timecode; + int v_skip_to_keyframe, a_skip_to_keyframe; - int64_t stop_timecode; + int64_t stop_timecode; - int last_aid; - int audio_tracks[MAX_A_STREAMS]; + int last_aid; + int audio_tracks[MAX_A_STREAMS]; } mkv_demuxer_t; #define REALHEADER_SIZE 16 @@ -208,59 +206,62 @@ extern int dvdsub_id; * \param nelem current number of elements in array * \param elsize size of one array element */ -static void av_noinline grow_array(void *arrayp, int nelem, size_t elsize) { - void **array = arrayp; - void *oldp = *array; - if (nelem & 31) - return; - if (nelem > UINT_MAX / elsize - 32) - *array = NULL; - else - *array = realloc(*array, (nelem + 32) * elsize); - if (!*array) - free(oldp); +static void av_noinline grow_array(void *arrayp, int nelem, size_t elsize) +{ + void **array = arrayp; + void *oldp = *array; + if (nelem & 31) + return; + if (nelem > UINT_MAX / elsize - 32) + *array = NULL; + else + *array = realloc(*array, (nelem + 32) * elsize); + if (!*array) + free(oldp); } -static mkv_track_t * -demux_mkv_find_track_by_num (mkv_demuxer_t *d, int n, int type) +static mkv_track_t *demux_mkv_find_track_by_num(mkv_demuxer_t *d, int n, + int type) { - int i, id; + int i, id; - for (i=0, id=0; i < d->num_tracks; i++) - if (d->tracks[i] != NULL && d->tracks[i]->type == type) - if (id++ == n) - return d->tracks[i]; + for (i = 0, id = 0; i < d->num_tracks; i++) + if (d->tracks[i] != NULL && d->tracks[i]->type == type) + if (id++ == n) + return d->tracks[i]; - return NULL; + return NULL; } -static void -add_cluster_position (mkv_demuxer_t *mkv_d, uint64_t position) +static void add_cluster_position(mkv_demuxer_t *mkv_d, uint64_t position) { - int i = mkv_d->num_cluster_pos; + int i = mkv_d->num_cluster_pos; - while (i--) - if (mkv_d->cluster_positions[i] == position) - return; + while (i--) + if (mkv_d->cluster_positions[i] == position) + return; - grow_array(&mkv_d->cluster_positions, mkv_d->num_cluster_pos, - sizeof(uint64_t)); - if (!mkv_d->cluster_positions) { - mkv_d->num_cluster_pos = 0; - return; - } - mkv_d->cluster_positions[mkv_d->num_cluster_pos++] = position; + grow_array(&mkv_d->cluster_positions, mkv_d->num_cluster_pos, + sizeof(uint64_t)); + if (!mkv_d->cluster_positions) { + mkv_d->num_cluster_pos = 0; + return; + } + mkv_d->cluster_positions[mkv_d->num_cluster_pos++] = position; } #define AAC_SYNC_EXTENSION_TYPE 0x02b7 -static int -aac_get_sample_rate_index (uint32_t sample_rate) +static int aac_get_sample_rate_index(uint32_t sample_rate) { - static const int srates[] = {92017, 75132, 55426, 46009, 37566, 27713, 23004, 18783, 13856, 11502, 9391, 0}; - int i = 0; - while (sample_rate < srates[i]) i++; - return i; + static const int srates[] = { + 92017, 75132, 55426, 46009, 37566, 27713, + 23004, 18783, 13856, 11502, 9391, 0 + }; + int i = 0; + while (sample_rate < srates[i]) + i++; + return i; } /** \brief Free cached demux packets @@ -271,166 +272,154 @@ aac_get_sample_rate_index (uint32_t sample_rate) * * \param demuxer The demuxer for which the cache is to be freed. */ -static void -free_cached_dps (demuxer_t *demuxer) +static void free_cached_dps(demuxer_t *demuxer) { - mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv; - mkv_track_t *track; - int i, k; + mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv; + mkv_track_t *track; + int i, k; - for (k = 0; k < mkv_d->num_tracks; k++) - { - track = mkv_d->tracks[k]; - for (i = 0; i < track->num_cached_dps; i++) - free_demux_packet (track->cached_dps[i]); - free(track->cached_dps); - track->cached_dps = NULL; - track->num_cached_dps = 0; - track->num_allocated_dps = 0; - track->max_pts = 0; + for (k = 0; k < mkv_d->num_tracks; k++) { + track = mkv_d->tracks[k]; + for (i = 0; i < track->num_cached_dps; i++) + free_demux_packet(track->cached_dps[i]); + free(track->cached_dps); + track->cached_dps = NULL; + track->num_cached_dps = 0; + track->num_allocated_dps = 0; + track->max_pts = 0; } } -static int -demux_mkv_decode (mkv_track_t *track, uint8_t *src, uint8_t **dest, - uint32_t *size, uint32_t type) +static int demux_mkv_decode(mkv_track_t *track, uint8_t *src, + uint8_t **dest, uint32_t *size, uint32_t type) { - int i, result; - int modified = 0; + int i, result; + int modified = 0; - *dest = src; - if (track->num_encodings <= 0) - return 0; + *dest = src; + if (track->num_encodings <= 0) + return 0; - for (i=0; inum_encodings; i++) - { - if (!(track->encodings[i].scope & type)) - continue; + for (i = 0; i < track->num_encodings; i++) { + if (!(track->encodings[i].scope & type)) + continue; #if CONFIG_ZLIB - if (track->encodings[i].comp_algo == 0) - { - /* zlib encoded track */ - z_stream zstream; + if (track->encodings[i].comp_algo == 0) { + /* zlib encoded track */ + z_stream zstream; - zstream.zalloc = (alloc_func) 0; - zstream.zfree = (free_func) 0; - zstream.opaque = (voidpf) 0; - if (inflateInit (&zstream) != Z_OK) - { - mp_msg (MSGT_DEMUX, MSGL_WARN, - MSGTR_MPDEMUX_MKV_ZlibInitializationFailed); - return modified; - } - zstream.next_in = (Bytef *) src; - zstream.avail_in = *size; - - modified = 1; - *dest = NULL; - zstream.avail_out = *size; - do { - *size += 4000; - *dest = realloc (*dest, *size); - zstream.next_out = (Bytef *) (*dest + zstream.total_out); - result = inflate (&zstream, Z_NO_FLUSH); - if (result != Z_OK && result != Z_STREAM_END) - { - mp_msg (MSGT_DEMUX, MSGL_WARN, - MSGTR_MPDEMUX_MKV_ZlibDecompressionFailed); - free(*dest); - *dest = NULL; - inflateEnd (&zstream); + zstream.zalloc = (alloc_func) 0; + zstream.zfree = (free_func) 0; + zstream.opaque = (voidpf) 0; + if (inflateInit(&zstream) != Z_OK) { + mp_msg(MSGT_DEMUX, MSGL_WARN, + MSGTR_MPDEMUX_MKV_ZlibInitializationFailed); return modified; - } - zstream.avail_out += 4000; - } while (zstream.avail_out == 4000 && - zstream.avail_in != 0 && result != Z_STREAM_END); + } + zstream.next_in = (Bytef *) src; + zstream.avail_in = *size; - *size = zstream.total_out; - inflateEnd (&zstream); + modified = 1; + *dest = NULL; + zstream.avail_out = *size; + do { + *size += 4000; + *dest = realloc(*dest, *size); + zstream.next_out = (Bytef *) (*dest + zstream.total_out); + result = inflate(&zstream, Z_NO_FLUSH); + if (result != Z_OK && result != Z_STREAM_END) { + mp_msg(MSGT_DEMUX, MSGL_WARN, + MSGTR_MPDEMUX_MKV_ZlibDecompressionFailed); + free(*dest); + *dest = NULL; + inflateEnd(&zstream); + return modified; + } + zstream.avail_out += 4000; + } while (zstream.avail_out == 4000 && zstream.avail_in != 0 + && result != Z_STREAM_END); + + *size = zstream.total_out; + inflateEnd(&zstream); } #endif - if (track->encodings[i].comp_algo == 2) - { - /* lzo encoded track */ - int dstlen = *size * 3; + if (track->encodings[i].comp_algo == 2) { + /* lzo encoded track */ + int dstlen = *size * 3; - *dest = NULL; - while (1) - { - int srclen = *size; - if (dstlen > SIZE_MAX - AV_LZO_OUTPUT_PADDING) goto lzo_fail; - *dest = realloc (*dest, dstlen + AV_LZO_OUTPUT_PADDING); - result = av_lzo1x_decode (*dest, &dstlen, src, &srclen); - if (result == 0) - break; - if (!(result & AV_LZO_OUTPUT_FULL)) - { -lzo_fail: - mp_msg (MSGT_DEMUX, MSGL_WARN, - MSGTR_MPDEMUX_MKV_LzoDecompressionFailed); - free(*dest); - *dest = NULL; - return modified; + *dest = NULL; + while (1) { + int srclen = *size; + if (dstlen > SIZE_MAX - AV_LZO_OUTPUT_PADDING) + goto lzo_fail; + *dest = realloc(*dest, dstlen + AV_LZO_OUTPUT_PADDING); + result = av_lzo1x_decode(*dest, &dstlen, src, &srclen); + if (result == 0) + break; + if (!(result & AV_LZO_OUTPUT_FULL)) { + lzo_fail: + mp_msg(MSGT_DEMUX, MSGL_WARN, + MSGTR_MPDEMUX_MKV_LzoDecompressionFailed); + free(*dest); + *dest = NULL; + return modified; } - mp_msg (MSGT_DEMUX, MSGL_DBG2, - "[mkv] lzo decompression buffer too small.\n"); - dstlen *= 2; + mp_msg(MSGT_DEMUX, MSGL_DBG2, + "[mkv] lzo decompression buffer too small.\n"); + dstlen *= 2; } - *size = dstlen; + *size = dstlen; } } - return modified; + return modified; } -static int -demux_mkv_read_info (demuxer_t *demuxer) +static int demux_mkv_read_info(demuxer_t *demuxer) { - mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv; - stream_t *s = demuxer->stream; - uint64_t length, l; - int il; - uint64_t tc_scale = 1000000; - long double duration = 0.; + mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv; + stream_t *s = demuxer->stream; + uint64_t length, l; + int il; + uint64_t tc_scale = 1000000; + long double duration = 0.; - length = ebml_read_length (s, NULL); - while (length > 0) - { - switch (ebml_read_id (s, &il)) - { + length = ebml_read_length(s, NULL); + while (length > 0) { + switch (ebml_read_id(s, &il)) { case MATROSKA_ID_TIMECODESCALE: - { - uint64_t num = ebml_read_uint (s, &l); + { + uint64_t num = ebml_read_uint(s, &l); if (num == EBML_UINT_INVALID) - return 1; + return 1; tc_scale = num; - mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + timecode scale: %"PRIu64"\n", - tc_scale); + mp_msg(MSGT_DEMUX, MSGL_V, + "[mkv] | + timecode scale: %" PRIu64 "\n", tc_scale); break; - } + } case MATROSKA_ID_DURATION: - { - long double num = ebml_read_float (s, &l); + { + long double num = ebml_read_float(s, &l); if (num == EBML_FLOAT_INVALID) - return 1; + return 1; duration = num; - mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + duration: %.3Lfs\n", - duration * tc_scale / 1000000000.0); + mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + duration: %.3Lfs\n", + duration * tc_scale / 1000000000.0); break; - } + } default: - ebml_read_skip (s, &l); - break; + ebml_read_skip(s, &l); + break; } - length -= l + il; + length -= l + il; } - mkv_d->tc_scale = tc_scale; - mkv_d->duration = duration * tc_scale / 1000000000.0; - return 0; + mkv_d->tc_scale = tc_scale; + mkv_d->duration = duration * tc_scale / 1000000000.0; + return 0; } /** @@ -438,2080 +427,1961 @@ demux_mkv_read_info (demuxer_t *demuxer) * \param encodings pointer to array * \param numencodings number of encodings in array */ -static void -demux_mkv_free_encodings(mkv_content_encoding_t *encodings, int numencodings) +static void demux_mkv_free_encodings(mkv_content_encoding_t *encodings, + int numencodings) { - while (numencodings-- > 0) - free(encodings[numencodings].comp_settings); - free(encodings); + while (numencodings-- > 0) + free(encodings[numencodings].comp_settings); + free(encodings); } -static int -demux_mkv_read_trackencodings (demuxer_t *demuxer, mkv_track_t *track) +static int demux_mkv_read_trackencodings(demuxer_t *demuxer, + mkv_track_t *track) { - stream_t *s = demuxer->stream; - mkv_content_encoding_t *ce, e; - uint64_t len, length, l; - int il, n; + stream_t *s = demuxer->stream; + mkv_content_encoding_t *ce, e; + uint64_t len, length, l; + int il, n; - ce = malloc (sizeof (*ce)); - n = 0; + ce = malloc(sizeof(*ce)); + n = 0; - len = length = ebml_read_length (s, &il); - len += il; - while (length > 0) - { - switch (ebml_read_id (s, &il)) - { + len = length = ebml_read_length(s, &il); + len += il; + while (length > 0) { + switch (ebml_read_id(s, &il)) { case MATROSKA_ID_CONTENTENCODING: - { + { uint64_t len; int i; - memset (&e, 0, sizeof (e)); + memset(&e, 0, sizeof(e)); e.scope = 1; - len = ebml_read_length (s, &i); + len = ebml_read_length(s, &i); l = len + i; - while (len > 0) - { + while (len > 0) { uint64_t num, l; int il; - switch (ebml_read_id (s, &il)) - { - case MATROSKA_ID_CONTENTENCODINGORDER: - num = ebml_read_uint (s, &l); + switch (ebml_read_id(s, &il)) { + case MATROSKA_ID_CONTENTENCODINGORDER: + num = ebml_read_uint(s, &l); if (num == EBML_UINT_INVALID) - goto err_out; + goto err_out; e.order = num; break; - case MATROSKA_ID_CONTENTENCODINGSCOPE: - num = ebml_read_uint (s, &l); + case MATROSKA_ID_CONTENTENCODINGSCOPE: + num = ebml_read_uint(s, &l); if (num == EBML_UINT_INVALID) - goto err_out; + goto err_out; e.scope = num; break; - case MATROSKA_ID_CONTENTENCODINGTYPE: - num = ebml_read_uint (s, &l); + case MATROSKA_ID_CONTENTENCODINGTYPE: + num = ebml_read_uint(s, &l); if (num == EBML_UINT_INVALID) - goto err_out; + goto err_out; e.type = num; break; - case MATROSKA_ID_CONTENTCOMPRESSION: - { - uint64_t le; + case MATROSKA_ID_CONTENTCOMPRESSION: + { + uint64_t le; - le = ebml_read_length (s, &i); - l = le + i; + le = ebml_read_length(s, &i); + l = le + i; - while (le > 0) - { - uint64_t l; - int il; + while (le > 0) { + uint64_t l; + int il; - switch (ebml_read_id (s, &il)) - { - case MATROSKA_ID_CONTENTCOMPALGO: - num = ebml_read_uint (s, &l); - if (num == EBML_UINT_INVALID) + switch (ebml_read_id(s, &il)) { + case MATROSKA_ID_CONTENTCOMPALGO: + num = ebml_read_uint(s, &l); + if (num == EBML_UINT_INVALID) goto err_out; - e.comp_algo = num; - break; + e.comp_algo = num; + break; - case MATROSKA_ID_CONTENTCOMPSETTINGS: - l = ebml_read_length (s, &i); - e.comp_settings = malloc (l); - stream_read (s, e.comp_settings, l); - e.comp_settings_len = l; - l += i; - break; + case MATROSKA_ID_CONTENTCOMPSETTINGS: + l = ebml_read_length(s, &i); + e.comp_settings = malloc(l); + stream_read(s, e.comp_settings, l); + e.comp_settings_len = l; + l += i; + break; - default: - ebml_read_skip (s, &l); - break; - } - le -= l + il; + default: + ebml_read_skip(s, &l); + break; } - - if (e.type == 1) - { - mp_msg(MSGT_DEMUX, MSGL_WARN, - MSGTR_MPDEMUX_MKV_TrackEncrypted, track->tnum); - } - else if (e.type != 0) - { - mp_msg(MSGT_DEMUX, MSGL_WARN, - MSGTR_MPDEMUX_MKV_UnknownContentEncoding, track->tnum); - } - - if (e.comp_algo != 0 && e.comp_algo != 2) - { - mp_msg (MSGT_DEMUX, MSGL_WARN, - MSGTR_MPDEMUX_MKV_UnknownCompression, - track->tnum, e.comp_algo); - } -#if !CONFIG_ZLIB - else if (e.comp_algo == 0) - { - mp_msg (MSGT_DEMUX, MSGL_WARN, - MSGTR_MPDEMUX_MKV_ZlibCompressionUnsupported, - track->tnum); - } -#endif - - break; + le -= l + il; } - default: - ebml_read_skip (s, &l); + if (e.type == 1) { + mp_msg(MSGT_DEMUX, MSGL_WARN, + MSGTR_MPDEMUX_MKV_TrackEncrypted, + track->tnum); + } else if (e.type != 0) { + mp_msg(MSGT_DEMUX, MSGL_WARN, + MSGTR_MPDEMUX_MKV_UnknownContentEncoding, + track->tnum); + } + + if (e.comp_algo != 0 && e.comp_algo != 2) { + mp_msg(MSGT_DEMUX, MSGL_WARN, + MSGTR_MPDEMUX_MKV_UnknownCompression, + track->tnum, e.comp_algo); + } +#if !CONFIG_ZLIB + else if (e.comp_algo == 0) { + mp_msg(MSGT_DEMUX, MSGL_WARN, + MSGTR_MPDEMUX_MKV_ZlibCompressionUnsupported, + track->tnum); + } +#endif + break; - } + } + + default: + ebml_read_skip(s, &l); + break; + } len -= l + il; - } - for (i=0; iencodings = ce; - track->num_encodings = n; - return len; + track->encodings = ce; + track->num_encodings = n; + return len; err_out: - demux_mkv_free_encodings(ce, n); - return 0; + demux_mkv_free_encodings(ce, n); + return 0; } -static int -demux_mkv_read_trackaudio (demuxer_t *demuxer, mkv_track_t *track) +static int demux_mkv_read_trackaudio(demuxer_t *demuxer, mkv_track_t *track) { - stream_t *s = demuxer->stream; - uint64_t len, length, l; - int il; + stream_t *s = demuxer->stream; + uint64_t len, length, l; + int il; - track->a_sfreq = 8000.0; - track->a_channels = 1; + track->a_sfreq = 8000.0; + track->a_channels = 1; - len = length = ebml_read_length (s, &il); - len += il; - while (length > 0) - { - switch (ebml_read_id (s, &il)) - { + len = length = ebml_read_length(s, &il); + len += il; + while (length > 0) { + switch (ebml_read_id(s, &il)) { case MATROSKA_ID_AUDIOSAMPLINGFREQ: - { - long double num = ebml_read_float (s, &l); + { + long double num = ebml_read_float(s, &l); if (num == EBML_FLOAT_INVALID) - return 0; + return 0; track->a_sfreq = num; - mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Sampling frequency: %f\n", - track->a_sfreq); + mp_msg(MSGT_DEMUX, MSGL_V, + "[mkv] | + Sampling frequency: %f\n", track->a_sfreq); break; - } + } case MATROSKA_ID_AUDIOBITDEPTH: - { - uint64_t num = ebml_read_uint (s, &l); + { + uint64_t num = ebml_read_uint(s, &l); if (num == EBML_UINT_INVALID) - return 0; + return 0; track->a_bps = num; - mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Bit depth: %u\n", - track->a_bps); + mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Bit depth: %u\n", + track->a_bps); break; - } + } case MATROSKA_ID_AUDIOCHANNELS: - { - uint64_t num = ebml_read_uint (s, &l); + { + uint64_t num = ebml_read_uint(s, &l); if (num == EBML_UINT_INVALID) - return 0; + return 0; track->a_channels = num; - mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Channels: %u\n", - track->a_channels); - break; - } - - default: - ebml_read_skip (s, &l); + mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Channels: %u\n", + track->a_channels); break; } - length -= l + il; + + default: + ebml_read_skip(s, &l); + break; + } + length -= l + il; } - return len; + return len; } -static int -demux_mkv_read_trackvideo (demuxer_t *demuxer, mkv_track_t *track) +static int demux_mkv_read_trackvideo(demuxer_t *demuxer, mkv_track_t *track) { - stream_t *s = demuxer->stream; - uint64_t len, length, l; - int il; + stream_t *s = demuxer->stream; + uint64_t len, length, l; + int il; - len = length = ebml_read_length (s, &il); - len += il; - while (length > 0) - { - switch (ebml_read_id (s, &il)) - { + len = length = ebml_read_length(s, &il); + len += il; + while (length > 0) { + switch (ebml_read_id(s, &il)) { case MATROSKA_ID_VIDEOFRAMERATE: - { - long double num = ebml_read_float (s, &l); + { + long double num = ebml_read_float(s, &l); if (num == EBML_FLOAT_INVALID) - return 0; + return 0; track->v_frate = num; - mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Frame rate: %f\n", - track->v_frate); + mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Frame rate: %f\n", + track->v_frate); if (track->v_frate > 0) - track->default_duration = 1 / track->v_frate; - break; - } - - case MATROSKA_ID_VIDEODISPLAYWIDTH: - { - uint64_t num = ebml_read_uint (s, &l); - if (num == EBML_UINT_INVALID) - return 0; - track->v_dwidth = num; - mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Display width: %u\n", - track->v_dwidth); - break; - } - - case MATROSKA_ID_VIDEODISPLAYHEIGHT: - { - uint64_t num = ebml_read_uint (s, &l); - if (num == EBML_UINT_INVALID) - return 0; - track->v_dheight = num; - mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Display height: %u\n", - track->v_dheight); - break; - } - - case MATROSKA_ID_VIDEOPIXELWIDTH: - { - uint64_t num = ebml_read_uint (s, &l); - if (num == EBML_UINT_INVALID) - return 0; - track->v_width = num; - mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Pixel width: %u\n", - track->v_width); - break; - } - - case MATROSKA_ID_VIDEOPIXELHEIGHT: - { - uint64_t num = ebml_read_uint (s, &l); - if (num == EBML_UINT_INVALID) - return 0; - track->v_height = num; - mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Pixel height: %u\n", - track->v_height); - break; - } - - default: - ebml_read_skip (s, &l); + track->default_duration = 1 / track->v_frate; break; } - length -= l + il; + + case MATROSKA_ID_VIDEODISPLAYWIDTH: + { + uint64_t num = ebml_read_uint(s, &l); + if (num == EBML_UINT_INVALID) + return 0; + track->v_dwidth = num; + mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Display width: %u\n", + track->v_dwidth); + break; + } + + case MATROSKA_ID_VIDEODISPLAYHEIGHT: + { + uint64_t num = ebml_read_uint(s, &l); + if (num == EBML_UINT_INVALID) + return 0; + track->v_dheight = num; + mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Display height: %u\n", + track->v_dheight); + break; + } + + case MATROSKA_ID_VIDEOPIXELWIDTH: + { + uint64_t num = ebml_read_uint(s, &l); + if (num == EBML_UINT_INVALID) + return 0; + track->v_width = num; + mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Pixel width: %u\n", + track->v_width); + break; + } + + case MATROSKA_ID_VIDEOPIXELHEIGHT: + { + uint64_t num = ebml_read_uint(s, &l); + if (num == EBML_UINT_INVALID) + return 0; + track->v_height = num; + mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Pixel height: %u\n", + track->v_height); + break; + } + + default: + ebml_read_skip(s, &l); + break; + } + length -= l + il; } - return len; + return len; } /** * \brief free any data associated with given track * \param track track of which to free data */ -static void -demux_mkv_free_trackentry(mkv_track_t *track) { - free (track->name); - free (track->codec_id); - free (track->language); - free (track->private_data); - free (track->audio_buf); - free (track->audio_timestamp); - demux_mkv_free_encodings(track->encodings, track->num_encodings); - free(track); +static void demux_mkv_free_trackentry(mkv_track_t *track) +{ + free(track->name); + free(track->codec_id); + free(track->language); + free(track->private_data); + free(track->audio_buf); + free(track->audio_timestamp); + demux_mkv_free_encodings(track->encodings, track->num_encodings); + free(track); } -static int -demux_mkv_read_trackentry (demuxer_t *demuxer) +static int demux_mkv_read_trackentry(demuxer_t *demuxer) { - mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv; - stream_t *s = demuxer->stream; - mkv_track_t *track; - uint64_t len, length, l; - int il; + mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv; + stream_t *s = demuxer->stream; + mkv_track_t *track; + uint64_t len, length, l; + int il; - track = calloc (1, sizeof (*track)); - /* set default values */ - track->default_track = 1; - track->name = 0; - track->language = strdup("eng"); + track = calloc(1, sizeof(*track)); + /* set default values */ + track->default_track = 1; + track->name = 0; + track->language = strdup("eng"); - len = length = ebml_read_length (s, &il); - len += il; - while (length > 0) - { - switch (ebml_read_id (s, &il)) - { + len = length = ebml_read_length(s, &il); + len += il; + while (length > 0) { + switch (ebml_read_id(s, &il)) { case MATROSKA_ID_TRACKNUMBER: - { - uint64_t num = ebml_read_uint (s, &l); + { + uint64_t num = ebml_read_uint(s, &l); if (num == EBML_UINT_INVALID) - goto err_out; + goto err_out; track->tnum = num; - mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Track number: %u\n", - track->tnum); + mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Track number: %u\n", + track->tnum); break; - } + } case MATROSKA_ID_TRACKNAME: - { - track->name = ebml_read_utf8 (s, &l); + track->name = ebml_read_utf8(s, &l); if (track->name == NULL) - goto err_out; - mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Name: %s\n", - track->name); + goto err_out; + mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Name: %s\n", + track->name); break; - } case MATROSKA_ID_TRACKTYPE: - { - uint64_t num = ebml_read_uint (s, &l); + { + uint64_t num = ebml_read_uint(s, &l); if (num == EBML_UINT_INVALID) - return 0; + return 0; track->type = num; - mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Track type: "); - switch (track->type) - { - case MATROSKA_TRACK_AUDIO: - mp_msg (MSGT_DEMUX, MSGL_V, "Audio\n"); + mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Track type: "); + switch (track->type) { + case MATROSKA_TRACK_AUDIO: + mp_msg(MSGT_DEMUX, MSGL_V, "Audio\n"); break; - case MATROSKA_TRACK_VIDEO: - mp_msg (MSGT_DEMUX, MSGL_V, "Video\n"); + case MATROSKA_TRACK_VIDEO: + mp_msg(MSGT_DEMUX, MSGL_V, "Video\n"); break; - case MATROSKA_TRACK_SUBTITLE: - mp_msg (MSGT_DEMUX, MSGL_V, "Subtitle\n"); + case MATROSKA_TRACK_SUBTITLE: + mp_msg(MSGT_DEMUX, MSGL_V, "Subtitle\n"); break; - default: - mp_msg (MSGT_DEMUX, MSGL_V, "unknown\n"); + default: + mp_msg(MSGT_DEMUX, MSGL_V, "unknown\n"); break; } break; - } + } case MATROSKA_ID_TRACKAUDIO: - mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Audio track\n"); - l = demux_mkv_read_trackaudio (demuxer, track); - if (l == 0) - goto err_out; - break; + mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Audio track\n"); + l = demux_mkv_read_trackaudio(demuxer, track); + if (l == 0) + goto err_out; + break; case MATROSKA_ID_TRACKVIDEO: - mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Video track\n"); - l = demux_mkv_read_trackvideo (demuxer, track); - if (l == 0) - goto err_out; - break; + mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Video track\n"); + l = demux_mkv_read_trackvideo(demuxer, track); + if (l == 0) + goto err_out; + break; case MATROSKA_ID_CODECID: - track->codec_id = ebml_read_ascii (s, &l); - if (track->codec_id == NULL) - goto err_out; - if (!strcmp (track->codec_id, MKV_V_MSCOMP) || - !strcmp (track->codec_id, MKV_A_ACM)) - track->ms_compat = 1; - else if (!strcmp (track->codec_id, MKV_S_VOBSUB)) - track->subtitle_type = MATROSKA_SUBTYPE_VOBSUB; - else if (!strcmp (track->codec_id, MKV_S_TEXTSSA) - || !strcmp (track->codec_id, MKV_S_TEXTASS) - || !strcmp (track->codec_id, MKV_S_SSA) - || !strcmp (track->codec_id, MKV_S_ASS)) - { - track->subtitle_type = MATROSKA_SUBTYPE_SSA; + track->codec_id = ebml_read_ascii(s, &l); + if (track->codec_id == NULL) + goto err_out; + if (!strcmp(track->codec_id, MKV_V_MSCOMP) + || !strcmp(track->codec_id, MKV_A_ACM)) + track->ms_compat = 1; + else if (!strcmp(track->codec_id, MKV_S_VOBSUB)) + track->subtitle_type = MATROSKA_SUBTYPE_VOBSUB; + else if (!strcmp(track->codec_id, MKV_S_TEXTSSA) + || !strcmp(track->codec_id, MKV_S_TEXTASS) + || !strcmp(track->codec_id, MKV_S_SSA) + || !strcmp(track->codec_id, MKV_S_ASS)) { + track->subtitle_type = MATROSKA_SUBTYPE_SSA; + } else if (!strcmp(track->codec_id, MKV_S_TEXTASCII)) + track->subtitle_type = MATROSKA_SUBTYPE_TEXT; + if (!strcmp(track->codec_id, MKV_S_TEXTUTF8)) { + track->subtitle_type = MATROSKA_SUBTYPE_TEXT; } - else if (!strcmp (track->codec_id, MKV_S_TEXTASCII)) - track->subtitle_type = MATROSKA_SUBTYPE_TEXT; - if (!strcmp (track->codec_id, MKV_S_TEXTUTF8)) - { - track->subtitle_type = MATROSKA_SUBTYPE_TEXT; - } - mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Codec ID: %s\n", - track->codec_id); - break; + mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Codec ID: %s\n", + track->codec_id); + break; case MATROSKA_ID_CODECPRIVATE: - { + { int x; - uint64_t num = ebml_read_length (s, &x); - // audit: cheap guard against overflows later.. - if (num > SIZE_MAX - 1000) return 0; + uint64_t num = ebml_read_length(s, &x); + // audit: cheap guard against overflows later.. + if (num > SIZE_MAX - 1000) + return 0; l = x + num; - track->private_data = malloc (num + AV_LZO_INPUT_PADDING); + track->private_data = malloc(num + AV_LZO_INPUT_PADDING); if (stream_read(s, track->private_data, num) != (int) num) - goto err_out; + goto err_out; track->private_size = num; - mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + CodecPrivate, length " - "%u\n", track->private_size); + mp_msg(MSGT_DEMUX, MSGL_V, + "[mkv] | + CodecPrivate, length " "%u\n", + track->private_size); break; - } + } case MATROSKA_ID_TRACKLANGUAGE: - free(track->language); - track->language = ebml_read_utf8 (s, &l); - if (track->language == NULL) - goto err_out; - mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Language: %s\n", - track->language); - break; + free(track->language); + track->language = ebml_read_utf8(s, &l); + if (track->language == NULL) + goto err_out; + mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Language: %s\n", + track->language); + break; case MATROSKA_ID_TRACKFLAGDEFAULT: - { - uint64_t num = ebml_read_uint (s, &l); + { + uint64_t num = ebml_read_uint(s, &l); if (num == EBML_UINT_INVALID) - goto err_out; + goto err_out; track->default_track = num; - mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Default flag: %u\n", - track->default_track); + mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Default flag: %u\n", + track->default_track); break; - } + } case MATROSKA_ID_TRACKDEFAULTDURATION: - { - uint64_t num = ebml_read_uint (s, &l); + { + uint64_t num = ebml_read_uint(s, &l); if (num == EBML_UINT_INVALID) - goto err_out; + goto err_out; if (num == 0) - mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Default duration: 0"); - else - { + mp_msg(MSGT_DEMUX, MSGL_V, + "[mkv] | + Default duration: 0"); + else { track->v_frate = 1000000000.0 / num; track->default_duration = num / 1000000000.0; - mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Default duration: " - "%.3fms ( = %.3f fps)\n",num/1000000.0,track->v_frate); - } + mp_msg(MSGT_DEMUX, MSGL_V, + "[mkv] | + Default duration: " + "%.3fms ( = %.3f fps)\n", num / 1000000.0, + track->v_frate); + } break; - } + } case MATROSKA_ID_TRACKENCODINGS: - l = demux_mkv_read_trackencodings (demuxer, track); - if (l == 0) - goto err_out; - break; + l = demux_mkv_read_trackencodings(demuxer, track); + if (l == 0) + goto err_out; + break; default: - ebml_read_skip (s, &l); - break; - } - length -= l + il; - } - - mkv_d->tracks[mkv_d->num_tracks++] = track; - return len; - -err_out: - demux_mkv_free_trackentry(track); - return 0; -} - -static int -demux_mkv_read_tracks (demuxer_t *demuxer) -{ - mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv; - stream_t *s = demuxer->stream; - uint64_t length, l; - int il; - - mkv_d->tracks = malloc (sizeof (*mkv_d->tracks)); - mkv_d->num_tracks = 0; - - length = ebml_read_length (s, NULL); - while (length > 0) - { - switch (ebml_read_id (s, &il)) - { - case MATROSKA_ID_TRACKENTRY: - mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + a track...\n"); - mkv_d->tracks = realloc (mkv_d->tracks, - (mkv_d->num_tracks+1) - *sizeof (*mkv_d->tracks)); - l = demux_mkv_read_trackentry (demuxer); - if (l == 0) - return 1; - break; - - default: - ebml_read_skip (s, &l); + ebml_read_skip(s, &l); break; } - length -= l + il; + length -= l + il; } - return 0; + + mkv_d->tracks[mkv_d->num_tracks++] = track; + return len; + +err_out: + demux_mkv_free_trackentry(track); + return 0; } -static int -demux_mkv_read_cues (demuxer_t *demuxer) +static int demux_mkv_read_tracks(demuxer_t *demuxer) { - mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv; - stream_t *s = demuxer->stream; - uint64_t length, l, time, track, pos; - off_t off; - int i, il; + mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv; + stream_t *s = demuxer->stream; + uint64_t length, l; + int il; - if (index_mode == 0) { - ebml_read_skip (s, NULL); + mkv_d->tracks = malloc(sizeof(*mkv_d->tracks)); + mkv_d->num_tracks = 0; + + length = ebml_read_length(s, NULL); + while (length > 0) { + switch (ebml_read_id(s, &il)) { + case MATROSKA_ID_TRACKENTRY: + mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + a track...\n"); + mkv_d->tracks = realloc(mkv_d->tracks, (mkv_d->num_tracks + 1) + * sizeof(*mkv_d->tracks)); + l = demux_mkv_read_trackentry(demuxer); + if (l == 0) + return 1; + break; + + default: + ebml_read_skip(s, &l); + break; + } + length -= l + il; + } return 0; - } - off = stream_tell (s); - for (i=0; iparsed_cues_num; i++) - if (mkv_d->parsed_cues[i] == off) - { - ebml_read_skip (s, NULL); +} + +static int demux_mkv_read_cues(demuxer_t *demuxer) +{ + mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv; + stream_t *s = demuxer->stream; + uint64_t length, l, time, track, pos; + off_t off; + int i, il; + + if (index_mode == 0) { + ebml_read_skip(s, NULL); return 0; - } - mkv_d->parsed_cues = realloc (mkv_d->parsed_cues, - (mkv_d->parsed_cues_num+1) - * sizeof (off_t)); - mkv_d->parsed_cues[mkv_d->parsed_cues_num++] = off; + } + off = stream_tell(s); + for (i = 0; i < mkv_d->parsed_cues_num; i++) + if (mkv_d->parsed_cues[i] == off) { + ebml_read_skip(s, NULL); + return 0; + } + mkv_d->parsed_cues = realloc(mkv_d->parsed_cues, + (mkv_d->parsed_cues_num + 1) * sizeof(off_t)); + mkv_d->parsed_cues[mkv_d->parsed_cues_num++] = off; - mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] /---- [ parsing cues ] -----------\n"); - length = ebml_read_length (s, NULL); + mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] /---- [ parsing cues ] -----------\n"); + length = ebml_read_length(s, NULL); - while (length > 0) - { - time = track = pos = EBML_UINT_INVALID; + while (length > 0) { + time = track = pos = EBML_UINT_INVALID; - switch (ebml_read_id (s, &il)) - { + switch (ebml_read_id(s, &il)) { case MATROSKA_ID_POINTENTRY: - { + { uint64_t len; - len = ebml_read_length (s, &i); + len = ebml_read_length(s, &i); l = len + i; - while (len > 0) - { + while (len > 0) { uint64_t l; int il; - switch (ebml_read_id (s, &il)) - { - case MATROSKA_ID_CUETIME: - time = ebml_read_uint (s, &l); + switch (ebml_read_id(s, &il)) { + case MATROSKA_ID_CUETIME: + time = ebml_read_uint(s, &l); break; - case MATROSKA_ID_CUETRACKPOSITION: - { - uint64_t le; + case MATROSKA_ID_CUETRACKPOSITION: + { + uint64_t le; - le = ebml_read_length (s, &i); - l = le + i; + le = ebml_read_length(s, &i); + l = le + i; - while (le > 0) - { - uint64_t l; - int il; + while (le > 0) { + uint64_t l; + int il; - switch (ebml_read_id (s, &il)) - { - case MATROSKA_ID_CUETRACK: - track = ebml_read_uint (s, &l); - break; + switch (ebml_read_id(s, &il)) { + case MATROSKA_ID_CUETRACK: + track = ebml_read_uint(s, &l); + break; - case MATROSKA_ID_CUECLUSTERPOSITION: - pos = ebml_read_uint (s, &l); - break; + case MATROSKA_ID_CUECLUSTERPOSITION: + pos = ebml_read_uint(s, &l); + break; - default: - ebml_read_skip (s, &l); - break; - } - le -= l + il; + default: + ebml_read_skip(s, &l); + break; } - break; + le -= l + il; } - - default: - ebml_read_skip (s, &l); break; - } + } + + default: + ebml_read_skip(s, &l); + break; + } len -= l + il; - } + } break; - } + } default: - ebml_read_skip (s, &l); - break; + ebml_read_skip(s, &l); + break; } - length -= l + il; + length -= l + il; - if (time != EBML_UINT_INVALID && track != EBML_UINT_INVALID - && pos != EBML_UINT_INVALID) - { - grow_array(&mkv_d->indexes, mkv_d->num_indexes, sizeof(mkv_index_t)); - if (!mkv_d->indexes) { - mkv_d->num_indexes = 0; - break; - } - mkv_d->indexes[mkv_d->num_indexes].tnum = track; - mkv_d->indexes[mkv_d->num_indexes].timecode = time; - mkv_d->indexes[mkv_d->num_indexes].filepos =mkv_d->segment_start+pos; - mp_msg (MSGT_DEMUX, MSGL_DBG2, "[mkv] |+ found cue point " - "for track %"PRIu64": timecode %"PRIu64", filepos: %"PRIu64"\n", - track, time, mkv_d->segment_start + pos); - mkv_d->num_indexes++; + if (time != EBML_UINT_INVALID && track != EBML_UINT_INVALID + && pos != EBML_UINT_INVALID) { + grow_array(&mkv_d->indexes, mkv_d->num_indexes, + sizeof(mkv_index_t)); + if (!mkv_d->indexes) { + mkv_d->num_indexes = 0; + break; + } + mkv_d->indexes[mkv_d->num_indexes].tnum = track; + mkv_d->indexes[mkv_d->num_indexes].timecode = time; + mkv_d->indexes[mkv_d->num_indexes].filepos = mkv_d->segment_start + + pos; + mp_msg(MSGT_DEMUX, MSGL_DBG2, + "[mkv] |+ found cue point " "for track %" PRIu64 + ": timecode %" PRIu64 ", filepos: %" PRIu64 "\n", track, + time, mkv_d->segment_start + pos); + mkv_d->num_indexes++; } } - mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] \\---- [ parsing cues ] -----------\n"); - return 0; + mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] \\---- [ parsing cues ] -----------\n"); + return 0; } -static int -demux_mkv_read_chapters (demuxer_t *demuxer) +static int demux_mkv_read_chapters(demuxer_t *demuxer) { - stream_t *s = demuxer->stream; - uint64_t length, l; - int il; + stream_t *s = demuxer->stream; + uint64_t length, l; + int il; - if (demuxer->chapters) - { - ebml_read_skip (s, NULL); - return 0; + if (demuxer->chapters) { + ebml_read_skip(s, NULL); + return 0; } - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] /---- [ parsing chapters ] ---------\n"); - length = ebml_read_length (s, NULL); + mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] /---- [ parsing chapters ] ---------\n"); + length = ebml_read_length(s, NULL); - while (length > 0) - { - switch (ebml_read_id (s, &il)) - { + while (length > 0) { + switch (ebml_read_id(s, &il)) { case MATROSKA_ID_EDITIONENTRY: - { + { uint64_t len; int i; - len = ebml_read_length (s, &i); + len = ebml_read_length(s, &i); l = len + i; - while (len > 0) - { + while (len > 0) { uint64_t l; int il; - switch (ebml_read_id (s, &il)) - { - case MATROSKA_ID_CHAPTERATOM: - { - uint64_t len, start=0, end=0; - char* name = 0; - int i; - int cid; + switch (ebml_read_id(s, &il)) { + case MATROSKA_ID_CHAPTERATOM: + { + uint64_t len, start = 0, end = 0; + char *name = 0; + int i; + int cid; - len = ebml_read_length (s, &i); - l = len + i; + len = ebml_read_length(s, &i); + l = len + i; - while (len > 0) + while (len > 0) { + uint64_t l; + int il; + + switch (ebml_read_id(s, &il)) { + case MATROSKA_ID_CHAPTERTIMESTART: + start = ebml_read_uint(s, &l) / 1000000; + break; + + case MATROSKA_ID_CHAPTERTIMEEND: + end = ebml_read_uint(s, &l) / 1000000; + break; + + case MATROSKA_ID_CHAPTERDISPLAY: { - uint64_t l; - int il; + uint64_t len; + int i; - switch (ebml_read_id (s, &il)) - { - case MATROSKA_ID_CHAPTERTIMESTART: - start = ebml_read_uint (s, &l) / 1000000; - break; + len = ebml_read_length(s, &i); + l = len + i; + while (len > 0) { + uint64_t l; + int il; - case MATROSKA_ID_CHAPTERTIMEEND: - end = ebml_read_uint (s, &l) / 1000000; - break; - - case MATROSKA_ID_CHAPTERDISPLAY: - { - uint64_t len; - int i; - - len = ebml_read_length (s, &i); - l = len + i; - while (len > 0) - { - uint64_t l; - int il; - - switch (ebml_read_id (s, &il)) - { - case MATROSKA_ID_CHAPSTRING: - name = ebml_read_utf8 (s, &l); - break; - default: - ebml_read_skip (s, &l); - break; - } - len -= l + il; - } - } - break; - - default: - ebml_read_skip (s, &l); - break; + switch (ebml_read_id(s, &il)) { + case MATROSKA_ID_CHAPSTRING: + name = ebml_read_utf8(s, &l); + break; + default: + ebml_read_skip(s, &l); + break; + } + len -= l + il; } - len -= l + il; } + break; - if (!name) + default: + ebml_read_skip(s, &l); + break; + } + len -= l + il; + } + + if (!name) name = strdup("(unnamed)"); - cid = demuxer_add_chapter(demuxer, name, start, end); + cid = demuxer_add_chapter(demuxer, name, start, end); - mp_msg(MSGT_DEMUX, MSGL_V, - "[mkv] Chapter %u from %02d:%02d:%02d." - "%03d to %02d:%02d:%02d.%03d, %s\n", - cid, - (int) (start / 60 / 60 / 1000), - (int) ((start / 60 / 1000) % 60), - (int) ((start / 1000) % 60), - (int) (start % 1000), - (int) (end / 60 / 60 / 1000), - (int) ((end / 60 / 1000) % 60), - (int) ((end / 1000) % 60), - (int) (end % 1000), name); + mp_msg(MSGT_DEMUX, MSGL_V, + "[mkv] Chapter %u from %02d:%02d:%02d." + "%03d to %02d:%02d:%02d.%03d, %s\n", cid, + (int) (start / 60 / 60 / 1000), + (int) ((start / 60 / 1000) % 60), + (int) ((start / 1000) % 60), + (int) (start % 1000), + (int) (end / 60 / 60 / 1000), + (int) ((end / 60 / 1000) % 60), + (int) ((end / 1000) % 60), + (int) (end % 1000), name); - free(name); - break; - } - - default: - ebml_read_skip (s, &l); + free(name); break; - } - len -= l + il; - } - break; - } - - default: - ebml_read_skip (s, &l); - break; - } - - length -= l + il; - } - - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] \\---- [ parsing chapters ] ---------\n"); - return 0; -} - -static int -demux_mkv_read_tags (demuxer_t *demuxer) -{ - ebml_read_skip (demuxer->stream, NULL); - return 0; -} - -static int -demux_mkv_read_attachments (demuxer_t *demuxer) -{ - stream_t *s = demuxer->stream; - uint64_t length, l; - int il; - - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] /---- [ parsing attachments ] ---------\n"); - length = ebml_read_length (s, NULL); - - while (length > 0) - { - switch (ebml_read_id (s, &il)) - { - case MATROSKA_ID_ATTACHEDFILE: - { - uint64_t len; - int i; - char* name = NULL; - char* mime = NULL; - char* data = NULL; - int data_size = 0; - - len = ebml_read_length (s, &i); - l = len + i; - - mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + an attachment...\n"); - - while (len > 0) - { - uint64_t l; - int il; - - switch (ebml_read_id (s, &il)) - { - case MATROSKA_ID_FILENAME: - name = ebml_read_utf8 (s, &l); - if (name == NULL) - return 0; - mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + FileName: %s\n", - name); - break; - - case MATROSKA_ID_FILEMIMETYPE: - mime = ebml_read_ascii (s, &l); - if (mime == NULL) - return 0; - mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + FileMimeType: %s\n", - mime); - break; - - case MATROSKA_ID_FILEDATA: - { - int x; - uint64_t num = ebml_read_length (s, &x); - l = x + num; - free(data); - data = malloc (num); - if (stream_read(s, data, num) != (int) num) - { - free(data); - return 0; - } - data_size = num; - mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + FileData, length " - "%u\n", data_size); - break; - } - - default: - ebml_read_skip (s, &l); - break; - } - len -= l + il; } - demuxer_add_attachment(demuxer, name, mime, data, data_size); - mp_msg(MSGT_DEMUX, MSGL_V, - "[mkv] Attachment: %s, %s, %u bytes\n", - name, mime, data_size); - break; + default: + ebml_read_skip(s, &l); + break; + } + len -= l + il; } - - default: - ebml_read_skip (s, &l); break; } - length -= l + il; + + default: + ebml_read_skip(s, &l); + break; + } + + length -= l + il; } - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] \\---- [ parsing attachments ] ---------\n"); - return 0; + mp_msg(MSGT_DEMUX, MSGL_V, + "[mkv] \\---- [ parsing chapters ] ---------\n"); + return 0; } -static int -demux_mkv_read_seekhead (demuxer_t *demuxer) +static int demux_mkv_read_tags(demuxer_t *demuxer) { - mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv; - stream_t *s = demuxer->stream; - uint64_t length, l, seek_pos, saved_pos, num; - uint32_t seek_id; - int i, il, res = 0; - off_t off; + ebml_read_skip(demuxer->stream, NULL); + return 0; +} - off = stream_tell (s); - for (i=0; iparsed_seekhead_num; i++) - if (mkv_d->parsed_seekhead[i] == off) - { - ebml_read_skip (s, NULL); - return 0; - } - mkv_d->parsed_seekhead = realloc (mkv_d->parsed_seekhead, - (mkv_d->parsed_seekhead_num+1) - * sizeof (off_t)); - mkv_d->parsed_seekhead[mkv_d->parsed_seekhead_num++] = off; +static int demux_mkv_read_attachments(demuxer_t *demuxer) +{ + stream_t *s = demuxer->stream; + uint64_t length, l; + int il; - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] /---- [ parsing seek head ] ---------\n"); - length = ebml_read_length (s, NULL); - /* off now holds the position of the next element after the seek head. */ - off = stream_tell (s) + length; - while (length > 0 && !res) - { + mp_msg(MSGT_DEMUX, MSGL_V, + "[mkv] /---- [ parsing attachments ] ---------\n"); + length = ebml_read_length(s, NULL); - seek_id = 0; - seek_pos = EBML_UINT_INVALID; - - switch (ebml_read_id (s, &il)) + while (length > 0) { + switch (ebml_read_id(s, &il)) { + case MATROSKA_ID_ATTACHEDFILE: { - case MATROSKA_ID_SEEKENTRY: - { uint64_t len; + int i; + char *name = NULL; + char *mime = NULL; + char *data = NULL; + int data_size = 0; - len = ebml_read_length (s, &i); + len = ebml_read_length(s, &i); l = len + i; - while (len > 0) - { + mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + an attachment...\n"); + + while (len > 0) { uint64_t l; int il; - switch (ebml_read_id (s, &il)) - { - case MATROSKA_ID_SEEKID: - num = ebml_read_uint (s, &l); - if (num != EBML_UINT_INVALID) - seek_id = num; + switch (ebml_read_id(s, &il)) { + case MATROSKA_ID_FILENAME: + name = ebml_read_utf8(s, &l); + if (name == NULL) + return 0; + mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + FileName: %s\n", + name); break; - case MATROSKA_ID_SEEKPOSITION: - seek_pos = ebml_read_uint (s, &l); + case MATROSKA_ID_FILEMIMETYPE: + mime = ebml_read_ascii(s, &l); + if (mime == NULL) + return 0; + mp_msg(MSGT_DEMUX, MSGL_V, + "[mkv] | + FileMimeType: %s\n", mime); break; - default: - ebml_read_skip (s, &l); + case MATROSKA_ID_FILEDATA: + { + int x; + uint64_t num = ebml_read_length(s, &x); + l = x + num; + free(data); + data = malloc(num); + if (stream_read(s, data, num) != (int) num) { + free(data); + return 0; + } + data_size = num; + mp_msg(MSGT_DEMUX, MSGL_V, + "[mkv] | + FileData, length " "%u\n", + data_size); break; - } + } + + default: + ebml_read_skip(s, &l); + break; + } len -= l + il; - } + } + demuxer_add_attachment(demuxer, name, mime, data, data_size); + mp_msg(MSGT_DEMUX, MSGL_V, + "[mkv] Attachment: %s, %s, %u bytes\n", name, mime, + data_size); break; - } + } default: - ebml_read_skip (s, &l); + ebml_read_skip(s, &l); break; } - length -= l + il; - - if (seek_id == 0 || seek_id == MATROSKA_ID_CLUSTER - || seek_pos == EBML_UINT_INVALID || - ((mkv_d->segment_start + seek_pos) >= (uint64_t)demuxer->movi_end)) - continue; - - saved_pos = stream_tell (s); - if (!stream_seek (s, mkv_d->segment_start + seek_pos)) - res = 1; - else - { - if (ebml_read_id (s, &il) != seek_id) - res = 1; - else - switch (seek_id) - { - case MATROSKA_ID_CUES: - if (demux_mkv_read_cues (demuxer)) - res = 1; - break; - - case MATROSKA_ID_TAGS: - if (demux_mkv_read_tags (demuxer)) - res = 1; - break; - - case MATROSKA_ID_SEEKHEAD: - if (demux_mkv_read_seekhead (demuxer)) - res = 1; - break; - - case MATROSKA_ID_CHAPTERS: - if (demux_mkv_read_chapters (demuxer)) - res = 1; - break; - } - } - - stream_seek (s, saved_pos); + length -= l + il; } - if (res) - { - /* If there was an error then try to skip this seek head. */ - if (stream_seek (s, off)) - res = 0; - } - else - if (length > 0) - stream_seek (s, stream_tell (s) + length); - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] \\---- [ parsing seek head ] ---------\n"); - return res; + + mp_msg(MSGT_DEMUX, MSGL_V, + "[mkv] \\---- [ parsing attachments ] ---------\n"); + return 0; } -static int -demux_mkv_open_video (demuxer_t *demuxer, mkv_track_t *track, int vid); -static int -demux_mkv_open_audio (demuxer_t *demuxer, mkv_track_t *track, int aid); -static int -demux_mkv_open_sub (demuxer_t *demuxer, mkv_track_t *track, int sid); - -static void -display_create_tracks (demuxer_t *demuxer) +static int demux_mkv_read_seekhead(demuxer_t *demuxer) { - mkv_demuxer_t *mkv_d = (mkv_demuxer_t *)demuxer->priv; - int i, vid=0, aid=0, sid=0; + mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv; + stream_t *s = demuxer->stream; + uint64_t length, l, seek_pos, saved_pos, num; + uint32_t seek_id; + int i, il, res = 0; + off_t off; - for (i=0; inum_tracks; i++) - { - char *type = "unknown", str[32]; - *str = '\0'; - switch (mkv_d->tracks[i]->type) - { - case MATROSKA_TRACK_VIDEO: - type = "video"; - demux_mkv_open_video(demuxer, mkv_d->tracks[i], vid); - if (mkv_d->tracks[i]->name) - mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VID_%d_NAME=%s\n", vid, mkv_d->tracks[i]->name); - sprintf (str, "-vid %u", vid++); - break; - case MATROSKA_TRACK_AUDIO: - type = "audio"; - demux_mkv_open_audio(demuxer, mkv_d->tracks[i], aid); - if (mkv_d->tracks[i]->name) - mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AID_%d_NAME=%s\n", aid, mkv_d->tracks[i]->name); - mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AID_%d_LANG=%s\n", aid, mkv_d->tracks[i]->language); - sprintf (str, "-aid %u, -alang %.5s",aid++,mkv_d->tracks[i]->language); - break; - case MATROSKA_TRACK_SUBTITLE: - type = "subtitles"; - demux_mkv_open_sub(demuxer, mkv_d->tracks[i], sid); - if (mkv_d->tracks[i]->name) - mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_SID_%d_NAME=%s\n", sid, mkv_d->tracks[i]->name); - mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_SID_%d_LANG=%s\n", sid, mkv_d->tracks[i]->language); - sprintf (str, "-sid %u, -slang %.5s",sid++,mkv_d->tracks[i]->language); - break; + off = stream_tell(s); + for (i = 0; i < mkv_d->parsed_seekhead_num; i++) + if (mkv_d->parsed_seekhead[i] == off) { + ebml_read_skip(s, NULL); + return 0; } - if (mkv_d->tracks[i]->name) - mp_msg(MSGT_DEMUX, MSGL_INFO, MSGTR_MPDEMUX_MKV_TrackIDName, - mkv_d->tracks[i]->tnum, type, mkv_d->tracks[i]->codec_id, mkv_d->tracks[i]->name, str); - else - mp_msg(MSGT_DEMUX, MSGL_INFO, MSGTR_MPDEMUX_MKV_TrackID, - mkv_d->tracks[i]->tnum, type, mkv_d->tracks[i]->codec_id, str); + mkv_d->parsed_seekhead = realloc(mkv_d->parsed_seekhead, + (mkv_d->parsed_seekhead_num + 1) + * sizeof(off_t)); + mkv_d->parsed_seekhead[mkv_d->parsed_seekhead_num++] = off; + + mp_msg(MSGT_DEMUX, MSGL_V, + "[mkv] /---- [ parsing seek head ] ---------\n"); + length = ebml_read_length(s, NULL); + /* off now holds the position of the next element after the seek head. */ + off = stream_tell(s) + length; + while (length > 0 && !res) { + + seek_id = 0; + seek_pos = EBML_UINT_INVALID; + + switch (ebml_read_id(s, &il)) { + case MATROSKA_ID_SEEKENTRY: + { + uint64_t len; + + len = ebml_read_length(s, &i); + l = len + i; + + while (len > 0) { + uint64_t l; + int il; + + switch (ebml_read_id(s, &il)) { + case MATROSKA_ID_SEEKID: + num = ebml_read_uint(s, &l); + if (num != EBML_UINT_INVALID) + seek_id = num; + break; + + case MATROSKA_ID_SEEKPOSITION: + seek_pos = ebml_read_uint(s, &l); + break; + + default: + ebml_read_skip(s, &l); + break; + } + len -= l + il; + } + + break; + } + + default: + ebml_read_skip(s, &l); + break; + } + length -= l + il; + + if (seek_id == 0 || seek_id == MATROSKA_ID_CLUSTER + || seek_pos == EBML_UINT_INVALID + || ((mkv_d->segment_start + seek_pos) >= + (uint64_t) demuxer->movi_end)) + continue; + + saved_pos = stream_tell(s); + if (!stream_seek(s, mkv_d->segment_start + seek_pos)) + res = 1; + else { + if (ebml_read_id(s, &il) != seek_id) + res = 1; + else + switch (seek_id) { + case MATROSKA_ID_CUES: + if (demux_mkv_read_cues(demuxer)) + res = 1; + break; + + case MATROSKA_ID_TAGS: + if (demux_mkv_read_tags(demuxer)) + res = 1; + break; + + case MATROSKA_ID_SEEKHEAD: + if (demux_mkv_read_seekhead(demuxer)) + res = 1; + break; + + case MATROSKA_ID_CHAPTERS: + if (demux_mkv_read_chapters(demuxer)) + res = 1; + break; + } + } + + stream_seek(s, saved_pos); + } + if (res) { + /* If there was an error then try to skip this seek head. */ + if (stream_seek(s, off)) + res = 0; + } else if (length > 0) + stream_seek(s, stream_tell(s) + length); + mp_msg(MSGT_DEMUX, MSGL_V, + "[mkv] \\---- [ parsing seek head ] ---------\n"); + return res; +} + +static int demux_mkv_open_video(demuxer_t *demuxer, mkv_track_t *track, + int vid); +static int demux_mkv_open_audio(demuxer_t *demuxer, mkv_track_t *track, + int aid); +static int demux_mkv_open_sub(demuxer_t *demuxer, mkv_track_t *track, + int sid); + +static void display_create_tracks(demuxer_t *demuxer) +{ + mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv; + int i, vid = 0, aid = 0, sid = 0; + + for (i = 0; i < mkv_d->num_tracks; i++) { + char *type = "unknown", str[32]; + *str = '\0'; + switch (mkv_d->tracks[i]->type) { + case MATROSKA_TRACK_VIDEO: + type = "video"; + demux_mkv_open_video(demuxer, mkv_d->tracks[i], vid); + if (mkv_d->tracks[i]->name) + mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VID_%d_NAME=%s\n", vid, + mkv_d->tracks[i]->name); + sprintf(str, "-vid %u", vid++); + break; + case MATROSKA_TRACK_AUDIO: + type = "audio"; + demux_mkv_open_audio(demuxer, mkv_d->tracks[i], aid); + if (mkv_d->tracks[i]->name) + mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AID_%d_NAME=%s\n", aid, + mkv_d->tracks[i]->name); + mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AID_%d_LANG=%s\n", aid, + mkv_d->tracks[i]->language); + sprintf(str, "-aid %u, -alang %.5s", aid++, + mkv_d->tracks[i]->language); + break; + case MATROSKA_TRACK_SUBTITLE: + type = "subtitles"; + demux_mkv_open_sub(demuxer, mkv_d->tracks[i], sid); + if (mkv_d->tracks[i]->name) + mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_SID_%d_NAME=%s\n", sid, + mkv_d->tracks[i]->name); + mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_SID_%d_LANG=%s\n", sid, + mkv_d->tracks[i]->language); + sprintf(str, "-sid %u, -slang %.5s", sid++, + mkv_d->tracks[i]->language); + break; + } + if (mkv_d->tracks[i]->name) + mp_msg(MSGT_DEMUX, MSGL_INFO, MSGTR_MPDEMUX_MKV_TrackIDName, + mkv_d->tracks[i]->tnum, type, mkv_d->tracks[i]->codec_id, + mkv_d->tracks[i]->name, str); + else + mp_msg(MSGT_DEMUX, MSGL_INFO, MSGTR_MPDEMUX_MKV_TrackID, + mkv_d->tracks[i]->tnum, type, mkv_d->tracks[i]->codec_id, + str); } } typedef struct { - char *id; - int fourcc; - int extradata; + char *id; + int fourcc; + int extradata; } videocodec_info_t; static const videocodec_info_t vinfo[] = { - { MKV_V_MPEG1, mmioFOURCC('m', 'p', 'g', '1'), 0 }, - { MKV_V_MPEG2, mmioFOURCC('m', 'p', 'g', '2'), 0 }, - { MKV_V_MPEG4_SP, mmioFOURCC('m', 'p', '4', 'v'), 1 }, - { MKV_V_MPEG4_ASP, mmioFOURCC('m', 'p', '4', 'v'), 1 }, - { MKV_V_MPEG4_AP, mmioFOURCC('m', 'p', '4', 'v'), 1 }, - { MKV_V_MPEG4_AVC, mmioFOURCC('a', 'v', 'c', '1'), 1 }, - { MKV_V_THEORA, mmioFOURCC('t', 'h', 'e', 'o'), 1 }, - { NULL, 0, 0 } + {MKV_V_MPEG1, mmioFOURCC('m', 'p', 'g', '1'), 0}, + {MKV_V_MPEG2, mmioFOURCC('m', 'p', 'g', '2'), 0}, + {MKV_V_MPEG4_SP, mmioFOURCC('m', 'p', '4', 'v'), 1}, + {MKV_V_MPEG4_ASP, mmioFOURCC('m', 'p', '4', 'v'), 1}, + {MKV_V_MPEG4_AP, mmioFOURCC('m', 'p', '4', 'v'), 1}, + {MKV_V_MPEG4_AVC, mmioFOURCC('a', 'v', 'c', '1'), 1}, + {MKV_V_THEORA, mmioFOURCC('t', 'h', 'e', 'o'), 1}, + {NULL, 0, 0} }; -static int -demux_mkv_open_video (demuxer_t *demuxer, mkv_track_t *track, int vid) +static int demux_mkv_open_video(demuxer_t *demuxer, mkv_track_t *track, + int vid) { - BITMAPINFOHEADER *bih; - void *ImageDesc = NULL; - sh_video_t *sh_v; + BITMAPINFOHEADER *bih; + void *ImageDesc = NULL; + sh_video_t *sh_v; - if (track->ms_compat) /* MS compatibility mode */ - { - BITMAPINFOHEADER *src; + if (track->ms_compat) { /* MS compatibility mode */ + BITMAPINFOHEADER *src; - if (track->private_data == NULL - || track->private_size < sizeof (BITMAPINFOHEADER)) - return 1; + if (track->private_data == NULL + || track->private_size < sizeof(BITMAPINFOHEADER)) + return 1; - src = (BITMAPINFOHEADER *) track->private_data; - bih = calloc (1, track->private_size); - bih->biSize = le2me_32 (src->biSize); - bih->biWidth = le2me_32 (src->biWidth); - bih->biHeight = le2me_32 (src->biHeight); - bih->biPlanes = le2me_16 (src->biPlanes); - bih->biBitCount = le2me_16 (src->biBitCount); - bih->biCompression = le2me_32 (src->biCompression); - bih->biSizeImage = le2me_32 (src->biSizeImage); - bih->biXPelsPerMeter = le2me_32 (src->biXPelsPerMeter); - bih->biYPelsPerMeter = le2me_32 (src->biYPelsPerMeter); - bih->biClrUsed = le2me_32 (src->biClrUsed); - bih->biClrImportant = le2me_32 (src->biClrImportant); - memcpy((char *) bih + sizeof (BITMAPINFOHEADER), - (char *) src + sizeof (BITMAPINFOHEADER), - track->private_size - sizeof (BITMAPINFOHEADER)); + src = (BITMAPINFOHEADER *) track->private_data; + bih = calloc(1, track->private_size); + bih->biSize = le2me_32(src->biSize); + bih->biWidth = le2me_32(src->biWidth); + bih->biHeight = le2me_32(src->biHeight); + bih->biPlanes = le2me_16(src->biPlanes); + bih->biBitCount = le2me_16(src->biBitCount); + bih->biCompression = le2me_32(src->biCompression); + bih->biSizeImage = le2me_32(src->biSizeImage); + bih->biXPelsPerMeter = le2me_32(src->biXPelsPerMeter); + bih->biYPelsPerMeter = le2me_32(src->biYPelsPerMeter); + bih->biClrUsed = le2me_32(src->biClrUsed); + bih->biClrImportant = le2me_32(src->biClrImportant); + memcpy((char *) bih + sizeof(BITMAPINFOHEADER), + (char *) src + sizeof(BITMAPINFOHEADER), + track->private_size - sizeof(BITMAPINFOHEADER)); - if (track->v_width == 0) - track->v_width = bih->biWidth; - if (track->v_height == 0) - track->v_height = bih->biHeight; - } - else - { - bih = calloc (1, sizeof (BITMAPINFOHEADER)); - bih->biSize = sizeof (BITMAPINFOHEADER); - bih->biWidth = track->v_width; - bih->biHeight = track->v_height; - bih->biBitCount = 24; - bih->biSizeImage = bih->biWidth * bih->biHeight * bih->biBitCount/8; + if (track->v_width == 0) + track->v_width = bih->biWidth; + if (track->v_height == 0) + track->v_height = bih->biHeight; + } else { + bih = calloc(1, sizeof(BITMAPINFOHEADER)); + bih->biSize = sizeof(BITMAPINFOHEADER); + bih->biWidth = track->v_width; + bih->biHeight = track->v_height; + bih->biBitCount = 24; + bih->biSizeImage = bih->biWidth * bih->biHeight * bih->biBitCount / 8; - if (track->private_size >= RVPROPERTIES_SIZE - && (!strcmp (track->codec_id, MKV_V_REALV10) - || !strcmp (track->codec_id, MKV_V_REALV20) - || !strcmp (track->codec_id, MKV_V_REALV30) - || !strcmp (track->codec_id, MKV_V_REALV40))) - { - unsigned char *dst, *src; - uint32_t type2; - unsigned int cnt; + if (track->private_size >= RVPROPERTIES_SIZE + && (!strcmp(track->codec_id, MKV_V_REALV10) + || !strcmp(track->codec_id, MKV_V_REALV20) + || !strcmp(track->codec_id, MKV_V_REALV30) + || !strcmp(track->codec_id, MKV_V_REALV40))) { + unsigned char *dst, *src; + uint32_t type2; + unsigned int cnt; - src = (uint8_t *)track->private_data + RVPROPERTIES_SIZE; + src = (uint8_t *) track->private_data + RVPROPERTIES_SIZE; - cnt = track->private_size - RVPROPERTIES_SIZE; - bih = realloc(bih, sizeof (BITMAPINFOHEADER)+8+cnt); - bih->biSize = 48+cnt; - bih->biPlanes = 1; - type2 = AV_RB32(src - 4); - if (type2 == 0x10003000 || type2 == 0x10003001) - bih->biCompression=mmioFOURCC('R','V','1','3'); - else - bih->biCompression=mmioFOURCC('R','V',track->codec_id[9],'0'); - dst = (unsigned char *) (bih + 1); - // copy type1 and type2 info from rv properties - memcpy(dst, src - 8, 8); - stream_read(demuxer->stream, dst+8, cnt); - track->realmedia = 1; + cnt = track->private_size - RVPROPERTIES_SIZE; + bih = realloc(bih, sizeof(BITMAPINFOHEADER) + 8 + cnt); + bih->biSize = 48 + cnt; + bih->biPlanes = 1; + type2 = AV_RB32(src - 4); + if (type2 == 0x10003000 || type2 == 0x10003001) + bih->biCompression = mmioFOURCC('R', 'V', '1', '3'); + else + bih->biCompression = + mmioFOURCC('R', 'V', track->codec_id[9], '0'); + dst = (unsigned char *) (bih + 1); + // copy type1 and type2 info from rv properties + memcpy(dst, src - 8, 8); + stream_read(demuxer->stream, dst + 8, cnt); + track->realmedia = 1; #ifdef CONFIG_QTX_CODECS - } - else if (track->private_size >= sizeof (ImageDescription) - && !strcmp(track->codec_id, MKV_V_QUICKTIME)) - { - ImageDescriptionPtr idesc; + } else if (track->private_size >= sizeof(ImageDescription) + && !strcmp(track->codec_id, MKV_V_QUICKTIME)) { + ImageDescriptionPtr idesc; - idesc = (ImageDescriptionPtr) track->private_data; - idesc->idSize = be2me_32 (idesc->idSize); - idesc->cType = be2me_32 (idesc->cType); - idesc->version = be2me_16 (idesc->version); - idesc->revisionLevel = be2me_16 (idesc->revisionLevel); - idesc->vendor = be2me_32 (idesc->vendor); - idesc->temporalQuality = be2me_32 (idesc->temporalQuality); - idesc->spatialQuality = be2me_32 (idesc->spatialQuality); - idesc->width = be2me_16 (idesc->width); - idesc->height = be2me_16 (idesc->height); - idesc->hRes = be2me_32 (idesc->hRes); - idesc->vRes = be2me_32 (idesc->vRes); - idesc->dataSize = be2me_32 (idesc->dataSize); - idesc->frameCount = be2me_16 (idesc->frameCount); - idesc->depth = be2me_16 (idesc->depth); - idesc->clutID = be2me_16 (idesc->clutID); - bih->biPlanes = 1; - bih->biCompression = idesc->cType; - ImageDesc = idesc; -#endif /* CONFIG_QTX_CODECS */ + idesc = (ImageDescriptionPtr) track->private_data; + idesc->idSize = be2me_32(idesc->idSize); + idesc->cType = be2me_32(idesc->cType); + idesc->version = be2me_16(idesc->version); + idesc->revisionLevel = be2me_16(idesc->revisionLevel); + idesc->vendor = be2me_32(idesc->vendor); + idesc->temporalQuality = be2me_32(idesc->temporalQuality); + idesc->spatialQuality = be2me_32(idesc->spatialQuality); + idesc->width = be2me_16(idesc->width); + idesc->height = be2me_16(idesc->height); + idesc->hRes = be2me_32(idesc->hRes); + idesc->vRes = be2me_32(idesc->vRes); + idesc->dataSize = be2me_32(idesc->dataSize); + idesc->frameCount = be2me_16(idesc->frameCount); + idesc->depth = be2me_16(idesc->depth); + idesc->clutID = be2me_16(idesc->clutID); + bih->biPlanes = 1; + bih->biCompression = idesc->cType; + ImageDesc = idesc; +#endif /* CONFIG_QTX_CODECS */ - } - else - { - const videocodec_info_t *vi = vinfo; - while (vi->id && strcmp(vi->id, track->codec_id)) vi++; - bih->biCompression = vi->fourcc; - if (vi->extradata && track->private_data && (track->private_size > 0)) - { - bih->biSize += track->private_size; - bih = realloc (bih, bih->biSize); - memcpy (bih + 1, track->private_data, track->private_size); + } else { + const videocodec_info_t *vi = vinfo; + while (vi->id && strcmp(vi->id, track->codec_id)) + vi++; + bih->biCompression = vi->fourcc; + if (vi->extradata && track->private_data + && (track->private_size > 0)) { + bih->biSize += track->private_size; + bih = realloc(bih, bih->biSize); + memcpy(bih + 1, track->private_data, track->private_size); + } + track->reorder_timecodes = user_correct_pts == 0; + if (!vi->id) { + mp_msg(MSGT_DEMUX, MSGL_WARN, MSGTR_MPDEMUX_MKV_UnknownCodecID, + track->codec_id, track->tnum); + free(bih); + return 1; } - track->reorder_timecodes = user_correct_pts == 0; - if (!vi->id) { - mp_msg (MSGT_DEMUX,MSGL_WARN, MSGTR_MPDEMUX_MKV_UnknownCodecID, - track->codec_id, track->tnum); - free(bih); - return 1; - } } } - sh_v = new_sh_video_vid (demuxer, track->tnum, vid); - sh_v->bih = bih; - sh_v->format = sh_v->bih->biCompression; - if (track->v_frate == 0.0) - track->v_frate = 25.0; - sh_v->fps = track->v_frate; - sh_v->frametime = 1 / track->v_frate; - sh_v->aspect = 0; - if (!track->realmedia) - { - sh_v->disp_w = track->v_width; - sh_v->disp_h = track->v_height; - if (track->v_dheight) - sh_v->aspect = (float)track->v_dwidth / (float)track->v_dheight; + sh_v = new_sh_video_vid(demuxer, track->tnum, vid); + sh_v->bih = bih; + sh_v->format = sh_v->bih->biCompression; + if (track->v_frate == 0.0) + track->v_frate = 25.0; + sh_v->fps = track->v_frate; + sh_v->frametime = 1 / track->v_frate; + sh_v->aspect = 0; + if (!track->realmedia) { + sh_v->disp_w = track->v_width; + sh_v->disp_h = track->v_height; + if (track->v_dheight) + sh_v->aspect = (float) track->v_dwidth / (float) track->v_dheight; + } else { + // vd_realvid.c will set aspect to disp_w/disp_h and rederive + // disp_w and disp_h from the RealVideo stream contents returned + // by the Real DLLs. If DisplayWidth/DisplayHeight was not set in + // the Matroska file then it has already been set to PixelWidth/Height + // by check_track_information. + sh_v->disp_w = track->v_dwidth; + sh_v->disp_h = track->v_dheight; } - else - { - // vd_realvid.c will set aspect to disp_w/disp_h and rederive - // disp_w and disp_h from the RealVideo stream contents returned - // by the Real DLLs. If DisplayWidth/DisplayHeight was not set in - // the Matroska file then it has already been set to PixelWidth/Height - // by check_track_information. - sh_v->disp_w = track->v_dwidth; - sh_v->disp_h = track->v_dheight; - } - sh_v->ImageDesc = ImageDesc; - mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] Aspect: %f\n", sh_v->aspect); + sh_v->ImageDesc = ImageDesc; + mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] Aspect: %f\n", sh_v->aspect); - sh_v->ds = demuxer->video; - return 0; + sh_v->ds = demuxer->video; + return 0; } -static int -demux_mkv_open_audio (demuxer_t *demuxer, mkv_track_t *track, int aid) +static int demux_mkv_open_audio(demuxer_t *demuxer, mkv_track_t *track, + int aid) { - mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv; - sh_audio_t *sh_a = new_sh_audio_aid(demuxer, track->tnum, aid); - demux_packet_t *dp; - if(!sh_a) return 1; - mkv_d->audio_tracks[mkv_d->last_aid] = track->tnum; + mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv; + sh_audio_t *sh_a = new_sh_audio_aid(demuxer, track->tnum, aid); + demux_packet_t *dp; + if (!sh_a) + return 1; + mkv_d->audio_tracks[mkv_d->last_aid] = track->tnum; - if (track->language && (strcmp(track->language, "und") != 0)) - sh_a->lang = strdup(track->language); - sh_a->default_track = track->default_track; - sh_a->ds = demuxer->audio; - sh_a->wf = malloc (sizeof (WAVEFORMATEX)); - if (track->ms_compat && (track->private_size >= sizeof(WAVEFORMATEX))) - { - WAVEFORMATEX *wf = (WAVEFORMATEX *)track->private_data; - sh_a->wf = realloc(sh_a->wf, track->private_size); - sh_a->wf->wFormatTag = le2me_16 (wf->wFormatTag); - sh_a->wf->nChannels = le2me_16 (wf->nChannels); - sh_a->wf->nSamplesPerSec = le2me_32 (wf->nSamplesPerSec); - sh_a->wf->nAvgBytesPerSec = le2me_32 (wf->nAvgBytesPerSec); - sh_a->wf->nBlockAlign = le2me_16 (wf->nBlockAlign); - sh_a->wf->wBitsPerSample = le2me_16 (wf->wBitsPerSample); - sh_a->wf->cbSize = track->private_size - sizeof(WAVEFORMATEX); - memcpy(sh_a->wf + 1, wf + 1, track->private_size - sizeof(WAVEFORMATEX)); - if (track->a_sfreq == 0.0) - track->a_sfreq = sh_a->wf->nSamplesPerSec; - if (track->a_channels == 0) - track->a_channels = sh_a->wf->nChannels; - if (track->a_bps == 0) - track->a_bps = sh_a->wf->wBitsPerSample; - track->a_formattag = sh_a->wf->wFormatTag; - } - else - { - memset(sh_a->wf, 0, sizeof (WAVEFORMATEX)); - if (!strcmp(track->codec_id, MKV_A_MP3) || - !strcmp(track->codec_id, MKV_A_MP2)) - track->a_formattag = 0x0055; - else if (!strncmp(track->codec_id, MKV_A_AC3, strlen(MKV_A_AC3))) - track->a_formattag = 0x2000; - else if (!strcmp(track->codec_id, MKV_A_DTS)) - track->a_formattag = 0x2001; - else if (!strcmp(track->codec_id, MKV_A_PCM) || - !strcmp(track->codec_id, MKV_A_PCM_BE)) - track->a_formattag = 0x0001; - else if (!strcmp(track->codec_id, MKV_A_AAC_2MAIN) || - !strncmp(track->codec_id, MKV_A_AAC_2LC, - strlen(MKV_A_AAC_2LC)) || - !strcmp(track->codec_id, MKV_A_AAC_2SSR) || - !strcmp(track->codec_id, MKV_A_AAC_4MAIN) || - !strncmp(track->codec_id, MKV_A_AAC_4LC, - strlen(MKV_A_AAC_4LC)) || - !strcmp(track->codec_id, MKV_A_AAC_4SSR) || - !strcmp(track->codec_id, MKV_A_AAC_4LTP) || - !strcmp(track->codec_id, MKV_A_AAC)) - track->a_formattag = mmioFOURCC('M', 'P', '4', 'A'); - else if (!strcmp(track->codec_id, MKV_A_VORBIS)) - { - if (track->private_data == NULL) + if (track->language && (strcmp(track->language, "und") != 0)) + sh_a->lang = strdup(track->language); + sh_a->default_track = track->default_track; + sh_a->ds = demuxer->audio; + sh_a->wf = malloc(sizeof(WAVEFORMATEX)); + if (track->ms_compat && (track->private_size >= sizeof(WAVEFORMATEX))) { + WAVEFORMATEX *wf = (WAVEFORMATEX *) track->private_data; + sh_a->wf = realloc(sh_a->wf, track->private_size); + sh_a->wf->wFormatTag = le2me_16(wf->wFormatTag); + sh_a->wf->nChannels = le2me_16(wf->nChannels); + sh_a->wf->nSamplesPerSec = le2me_32(wf->nSamplesPerSec); + sh_a->wf->nAvgBytesPerSec = le2me_32(wf->nAvgBytesPerSec); + sh_a->wf->nBlockAlign = le2me_16(wf->nBlockAlign); + sh_a->wf->wBitsPerSample = le2me_16(wf->wBitsPerSample); + sh_a->wf->cbSize = track->private_size - sizeof(WAVEFORMATEX); + memcpy(sh_a->wf + 1, wf + 1, + track->private_size - sizeof(WAVEFORMATEX)); + if (track->a_sfreq == 0.0) + track->a_sfreq = sh_a->wf->nSamplesPerSec; + if (track->a_channels == 0) + track->a_channels = sh_a->wf->nChannels; + if (track->a_bps == 0) + track->a_bps = sh_a->wf->wBitsPerSample; + track->a_formattag = sh_a->wf->wFormatTag; + } else { + memset(sh_a->wf, 0, sizeof(WAVEFORMATEX)); + if (!strcmp(track->codec_id, MKV_A_MP3) + || !strcmp(track->codec_id, MKV_A_MP2)) + track->a_formattag = 0x0055; + else if (!strncmp(track->codec_id, MKV_A_AC3, strlen(MKV_A_AC3))) + track->a_formattag = 0x2000; + else if (!strcmp(track->codec_id, MKV_A_DTS)) + track->a_formattag = 0x2001; + else if (!strcmp(track->codec_id, MKV_A_PCM) + || !strcmp(track->codec_id, MKV_A_PCM_BE)) + track->a_formattag = 0x0001; + else if (!strcmp(track->codec_id, MKV_A_AAC_2MAIN) + || !strncmp(track->codec_id, MKV_A_AAC_2LC, + strlen(MKV_A_AAC_2LC)) + || !strcmp(track->codec_id, MKV_A_AAC_2SSR) + || !strcmp(track->codec_id, MKV_A_AAC_4MAIN) + || !strncmp(track->codec_id, MKV_A_AAC_4LC, + strlen(MKV_A_AAC_4LC)) + || !strcmp(track->codec_id, MKV_A_AAC_4SSR) + || !strcmp(track->codec_id, MKV_A_AAC_4LTP) + || !strcmp(track->codec_id, MKV_A_AAC)) + track->a_formattag = mmioFOURCC('M', 'P', '4', 'A'); + else if (!strcmp(track->codec_id, MKV_A_VORBIS)) { + if (track->private_data == NULL) + return 1; + track->a_formattag = mmioFOURCC('v', 'r', 'b', 's'); + } else if (!strcmp(track->codec_id, MKV_A_QDMC)) + track->a_formattag = mmioFOURCC('Q', 'D', 'M', 'C'); + else if (!strcmp(track->codec_id, MKV_A_QDMC2)) + track->a_formattag = mmioFOURCC('Q', 'D', 'M', '2'); + else if (!strcmp(track->codec_id, MKV_A_WAVPACK)) + track->a_formattag = mmioFOURCC('W', 'V', 'P', 'K'); + else if (!strcmp(track->codec_id, MKV_A_TRUEHD)) + track->a_formattag = mmioFOURCC('T', 'R', 'H', 'D'); + else if (!strcmp(track->codec_id, MKV_A_FLAC)) { + if (track->private_data == NULL || track->private_size == 0) { + mp_msg(MSGT_DEMUX, MSGL_WARN, + MSGTR_MPDEMUX_MKV_FlacTrackDoesNotContainValidHeaders); + return 1; + } + track->a_formattag = mmioFOURCC('f', 'L', 'a', 'C'); + } else if (track->private_size >= RAPROPERTIES4_SIZE) { + if (!strcmp(track->codec_id, MKV_A_REAL28)) + track->a_formattag = mmioFOURCC('2', '8', '_', '8'); + else if (!strcmp(track->codec_id, MKV_A_REALATRC)) + track->a_formattag = mmioFOURCC('a', 't', 'r', 'c'); + else if (!strcmp(track->codec_id, MKV_A_REALCOOK)) + track->a_formattag = mmioFOURCC('c', 'o', 'o', 'k'); + else if (!strcmp(track->codec_id, MKV_A_REALDNET)) + track->a_formattag = mmioFOURCC('d', 'n', 'e', 't'); + else if (!strcmp(track->codec_id, MKV_A_REALSIPR)) + track->a_formattag = mmioFOURCC('s', 'i', 'p', 'r'); + } else { + mp_msg(MSGT_DEMUX, MSGL_WARN, MSGTR_MPDEMUX_MKV_UnknownAudioCodec, + track->codec_id, track->tnum); + free_sh_audio(demuxer, track->tnum); return 1; - track->a_formattag = mmioFOURCC('v', 'r', 'b', 's'); - } - else if (!strcmp(track->codec_id, MKV_A_QDMC)) - track->a_formattag = mmioFOURCC('Q', 'D', 'M', 'C'); - else if (!strcmp(track->codec_id, MKV_A_QDMC2)) - track->a_formattag = mmioFOURCC('Q', 'D', 'M', '2'); - else if (!strcmp(track->codec_id, MKV_A_WAVPACK)) - track->a_formattag = mmioFOURCC('W', 'V', 'P', 'K'); - else if (!strcmp(track->codec_id, MKV_A_TRUEHD)) - track->a_formattag = mmioFOURCC('T', 'R', 'H', 'D'); - else if (!strcmp(track->codec_id, MKV_A_FLAC)) - { - if (track->private_data == NULL || track->private_size == 0) - { - mp_msg (MSGT_DEMUX, MSGL_WARN, - MSGTR_MPDEMUX_MKV_FlacTrackDoesNotContainValidHeaders); - return 1; - } - track->a_formattag = mmioFOURCC ('f', 'L', 'a', 'C'); - } - else if (track->private_size >= RAPROPERTIES4_SIZE) - { - if (!strcmp(track->codec_id, MKV_A_REAL28)) - track->a_formattag = mmioFOURCC('2', '8', '_', '8'); - else if (!strcmp(track->codec_id, MKV_A_REALATRC)) - track->a_formattag = mmioFOURCC('a', 't', 'r', 'c'); - else if (!strcmp(track->codec_id, MKV_A_REALCOOK)) - track->a_formattag = mmioFOURCC('c', 'o', 'o', 'k'); - else if (!strcmp(track->codec_id, MKV_A_REALDNET)) - track->a_formattag = mmioFOURCC('d', 'n', 'e', 't'); - else if (!strcmp(track->codec_id, MKV_A_REALSIPR)) - track->a_formattag = mmioFOURCC('s', 'i', 'p', 'r'); - } - else - { - mp_msg (MSGT_DEMUX, MSGL_WARN, MSGTR_MPDEMUX_MKV_UnknownAudioCodec, - track->codec_id, track->tnum); - free_sh_audio(demuxer, track->tnum); - return 1; } } - sh_a->format = track->a_formattag; - sh_a->wf->wFormatTag = track->a_formattag; - sh_a->channels = track->a_channels; - sh_a->wf->nChannels = track->a_channels; - sh_a->samplerate = (uint32_t) track->a_sfreq; - sh_a->wf->nSamplesPerSec = (uint32_t) track->a_sfreq; - if (track->a_bps == 0) - { - sh_a->samplesize = 2; - sh_a->wf->wBitsPerSample = 16; + sh_a->format = track->a_formattag; + sh_a->wf->wFormatTag = track->a_formattag; + sh_a->channels = track->a_channels; + sh_a->wf->nChannels = track->a_channels; + sh_a->samplerate = (uint32_t) track->a_sfreq; + sh_a->wf->nSamplesPerSec = (uint32_t) track->a_sfreq; + if (track->a_bps == 0) { + sh_a->samplesize = 2; + sh_a->wf->wBitsPerSample = 16; + } else { + sh_a->samplesize = track->a_bps / 8; + sh_a->wf->wBitsPerSample = track->a_bps; } - else - { - sh_a->samplesize = track->a_bps / 8; - sh_a->wf->wBitsPerSample = track->a_bps; - } - if (track->a_formattag == 0x0055) /* MP3 || MP2 */ - { - sh_a->wf->nAvgBytesPerSec = 16000; - sh_a->wf->nBlockAlign = 1152; - } - else if ((track->a_formattag == 0x2000) || /* AC3 */ - (track->a_formattag == 0x2001)) /* DTS */ - { - free(sh_a->wf); - sh_a->wf = NULL; - } - else if (track->a_formattag == 0x0001) /* PCM || PCM_BE */ - { - sh_a->wf->nAvgBytesPerSec = sh_a->channels * sh_a->samplerate*2; - sh_a->wf->nBlockAlign = sh_a->wf->nAvgBytesPerSec; - if (!strcmp(track->codec_id, MKV_A_PCM_BE)) - sh_a->format = mmioFOURCC('t', 'w', 'o', 's'); - } - else if (!strcmp(track->codec_id, MKV_A_QDMC) || - !strcmp(track->codec_id, MKV_A_QDMC2)) - { - sh_a->wf->nAvgBytesPerSec = 16000; - sh_a->wf->nBlockAlign = 1486; - track->fix_i_bps = 1; - track->qt_last_a_pts = 0.0; - if (track->private_data != NULL) - { - sh_a->codecdata=malloc(track->private_size); - memcpy (sh_a->codecdata, track->private_data, - track->private_size); - sh_a->codecdata_len = track->private_size; + if (track->a_formattag == 0x0055) { /* MP3 || MP2 */ + sh_a->wf->nAvgBytesPerSec = 16000; + sh_a->wf->nBlockAlign = 1152; + } else if ((track->a_formattag == 0x2000) || /* AC3 */ + (track->a_formattag == 0x2001)) { /* DTS */ + free(sh_a->wf); + sh_a->wf = NULL; + } else if (track->a_formattag == 0x0001) { /* PCM || PCM_BE */ + sh_a->wf->nAvgBytesPerSec = sh_a->channels * sh_a->samplerate * 2; + sh_a->wf->nBlockAlign = sh_a->wf->nAvgBytesPerSec; + if (!strcmp(track->codec_id, MKV_A_PCM_BE)) + sh_a->format = mmioFOURCC('t', 'w', 'o', 's'); + } else if (!strcmp(track->codec_id, MKV_A_QDMC) + || !strcmp(track->codec_id, MKV_A_QDMC2)) { + sh_a->wf->nAvgBytesPerSec = 16000; + sh_a->wf->nBlockAlign = 1486; + track->fix_i_bps = 1; + track->qt_last_a_pts = 0.0; + if (track->private_data != NULL) { + sh_a->codecdata = malloc(track->private_size); + memcpy(sh_a->codecdata, track->private_data, track->private_size); + sh_a->codecdata_len = track->private_size; } - } - else if (track->a_formattag == mmioFOURCC('M', 'P', '4', 'A')) - { - int profile, srate_idx; + } else if (track->a_formattag == mmioFOURCC('M', 'P', '4', 'A')) { + int profile, srate_idx; - sh_a->wf->nAvgBytesPerSec = 16000; - sh_a->wf->nBlockAlign = 1024; + sh_a->wf->nAvgBytesPerSec = 16000; + sh_a->wf->nBlockAlign = 1024; - if (!strcmp (track->codec_id, MKV_A_AAC) && - (NULL != track->private_data)) - { - sh_a->codecdata=malloc(track->private_size); - memcpy (sh_a->codecdata, track->private_data, - track->private_size); - sh_a->codecdata_len = track->private_size; - return 0; + if (!strcmp(track->codec_id, MKV_A_AAC) + && (NULL != track->private_data)) { + sh_a->codecdata = malloc(track->private_size); + memcpy(sh_a->codecdata, track->private_data, track->private_size); + sh_a->codecdata_len = track->private_size; + return 0; } - /* Recreate the 'private data' */ - /* which faad2 uses in its initialization */ - srate_idx = aac_get_sample_rate_index (sh_a->samplerate); - if (!strncmp (&track->codec_id[12], "MAIN", 4)) - profile = 0; - else if (!strncmp (&track->codec_id[12], "LC", 2)) - profile = 1; - else if (!strncmp (&track->codec_id[12], "SSR", 3)) - profile = 2; - else - profile = 3; - sh_a->codecdata = malloc (5); - sh_a->codecdata[0] = ((profile+1) << 3) | ((srate_idx&0xE) >> 1); - sh_a->codecdata[1] = ((srate_idx&0x1)<<7)|(track->a_channels<<3); + /* Recreate the 'private data' */ + /* which faad2 uses in its initialization */ + srate_idx = aac_get_sample_rate_index(sh_a->samplerate); + if (!strncmp(&track->codec_id[12], "MAIN", 4)) + profile = 0; + else if (!strncmp(&track->codec_id[12], "LC", 2)) + profile = 1; + else if (!strncmp(&track->codec_id[12], "SSR", 3)) + profile = 2; + else + profile = 3; + sh_a->codecdata = malloc(5); + sh_a->codecdata[0] = ((profile + 1) << 3) | ((srate_idx & 0xE) >> 1); + sh_a->codecdata[1] = + ((srate_idx & 0x1) << 7) | (track->a_channels << 3); - if (strstr(track->codec_id, "SBR") != NULL) - { - /* HE-AAC (aka SBR AAC) */ - sh_a->codecdata_len = 5; + if (strstr(track->codec_id, "SBR") != NULL) { + /* HE-AAC (aka SBR AAC) */ + sh_a->codecdata_len = 5; - sh_a->samplerate *= 2; - sh_a->wf->nSamplesPerSec *= 2; - srate_idx = aac_get_sample_rate_index(sh_a->samplerate); - sh_a->codecdata[2] = AAC_SYNC_EXTENSION_TYPE >> 3; - sh_a->codecdata[3] = ((AAC_SYNC_EXTENSION_TYPE&0x07)<<5) | 5; - sh_a->codecdata[4] = (1 << 7) | (srate_idx << 3); - track->default_duration = 1024.0 / (sh_a->samplerate / 2); + sh_a->samplerate *= 2; + sh_a->wf->nSamplesPerSec *= 2; + srate_idx = aac_get_sample_rate_index(sh_a->samplerate); + sh_a->codecdata[2] = AAC_SYNC_EXTENSION_TYPE >> 3; + sh_a->codecdata[3] = ((AAC_SYNC_EXTENSION_TYPE & 0x07) << 5) | 5; + sh_a->codecdata[4] = (1 << 7) | (srate_idx << 3); + track->default_duration = 1024.0 / (sh_a->samplerate / 2); + } else { + sh_a->codecdata_len = 2; + track->default_duration = 1024.0 / (float) sh_a->samplerate; } - else - { - sh_a->codecdata_len = 2; - track->default_duration = 1024.0 / (float)sh_a->samplerate; - } - } - else if (track->a_formattag == mmioFOURCC('v', 'r', 'b', 's')) /* VORBIS */ - { - sh_a->wf->cbSize = track->private_size; - sh_a->wf = realloc(sh_a->wf, sizeof(WAVEFORMATEX) + sh_a->wf->cbSize); - memcpy((unsigned char *) (sh_a->wf+1), track->private_data, sh_a->wf->cbSize); - } - else if (track->private_size >= RAPROPERTIES4_SIZE - && !strncmp (track->codec_id, MKV_A_REALATRC, 7)) - { - /* Common initialization for all RealAudio codecs */ - unsigned char *src = track->private_data; - int codecdata_length, version; - int flavor; + } else if (track->a_formattag == mmioFOURCC('v', 'r', 'b', 's')) { /* VORBIS */ + sh_a->wf->cbSize = track->private_size; + sh_a->wf = realloc(sh_a->wf, sizeof(WAVEFORMATEX) + sh_a->wf->cbSize); + memcpy((unsigned char *) (sh_a->wf + 1), track->private_data, + sh_a->wf->cbSize); + } else if (track->private_size >= RAPROPERTIES4_SIZE + && !strncmp(track->codec_id, MKV_A_REALATRC, 7)) { + /* Common initialization for all RealAudio codecs */ + unsigned char *src = track->private_data; + int codecdata_length, version; + int flavor; - sh_a->wf->nAvgBytesPerSec = 0; /* FIXME !? */ + sh_a->wf->nAvgBytesPerSec = 0; /* FIXME !? */ - version = AV_RB16(src + 4); - flavor = AV_RB16(src + 22); - track->coded_framesize = AV_RB32(src + 24); - track->sub_packet_h = AV_RB16(src + 40); - sh_a->wf->nBlockAlign = - track->audiopk_size = AV_RB16(src + 42); - track->sub_packet_size = AV_RB16(src + 44); - if (version == 4) - { - src += RAPROPERTIES4_SIZE; - src += src[0] + 1; - src += src[0] + 1; - } - else - src += RAPROPERTIES5_SIZE; + version = AV_RB16(src + 4); + flavor = AV_RB16(src + 22); + track->coded_framesize = AV_RB32(src + 24); + track->sub_packet_h = AV_RB16(src + 40); + sh_a->wf->nBlockAlign = track->audiopk_size = AV_RB16(src + 42); + track->sub_packet_size = AV_RB16(src + 44); + if (version == 4) { + src += RAPROPERTIES4_SIZE; + src += src[0] + 1; + src += src[0] + 1; + } else + src += RAPROPERTIES5_SIZE; - src += 3; - if (version == 5) - src++; - codecdata_length = AV_RB32(src); - src += 4; - sh_a->wf->cbSize = codecdata_length; - sh_a->wf = realloc (sh_a->wf, - sizeof (WAVEFORMATEX) + - sh_a->wf->cbSize); - memcpy(((char *)(sh_a->wf + 1)), src, codecdata_length); + src += 3; + if (version == 5) + src++; + codecdata_length = AV_RB32(src); + src += 4; + sh_a->wf->cbSize = codecdata_length; + sh_a->wf = realloc(sh_a->wf, sizeof(WAVEFORMATEX) + sh_a->wf->cbSize); + memcpy(((char *) (sh_a->wf + 1)), src, codecdata_length); - switch (track->a_formattag) { + switch (track->a_formattag) { case mmioFOURCC('a', 't', 'r', 'c'): - sh_a->wf->nAvgBytesPerSec = atrc_fl2bps[flavor]; - sh_a->wf->nBlockAlign = track->sub_packet_size; - track->audio_buf = malloc(track->sub_packet_h * track->audiopk_size); - track->audio_timestamp = malloc(track->sub_packet_h * sizeof(float)); - break; + sh_a->wf->nAvgBytesPerSec = atrc_fl2bps[flavor]; + sh_a->wf->nBlockAlign = track->sub_packet_size; + track->audio_buf = + malloc(track->sub_packet_h * track->audiopk_size); + track->audio_timestamp = + malloc(track->sub_packet_h * sizeof(float)); + break; case mmioFOURCC('c', 'o', 'o', 'k'): - sh_a->wf->nAvgBytesPerSec = cook_fl2bps[flavor]; - sh_a->wf->nBlockAlign = track->sub_packet_size; - track->audio_buf = malloc(track->sub_packet_h * track->audiopk_size); - track->audio_timestamp = malloc(track->sub_packet_h * sizeof(float)); - break; + sh_a->wf->nAvgBytesPerSec = cook_fl2bps[flavor]; + sh_a->wf->nBlockAlign = track->sub_packet_size; + track->audio_buf = + malloc(track->sub_packet_h * track->audiopk_size); + track->audio_timestamp = + malloc(track->sub_packet_h * sizeof(float)); + break; case mmioFOURCC('s', 'i', 'p', 'r'): - sh_a->wf->nAvgBytesPerSec = sipr_fl2bps[flavor]; - sh_a->wf->nBlockAlign = track->coded_framesize; - track->audio_buf = malloc(track->sub_packet_h * track->audiopk_size); - track->audio_timestamp = malloc(track->sub_packet_h * sizeof(float)); - break; + sh_a->wf->nAvgBytesPerSec = sipr_fl2bps[flavor]; + sh_a->wf->nBlockAlign = track->coded_framesize; + track->audio_buf = + malloc(track->sub_packet_h * track->audiopk_size); + track->audio_timestamp = + malloc(track->sub_packet_h * sizeof(float)); + break; case mmioFOURCC('2', '8', '_', '8'): - sh_a->wf->nAvgBytesPerSec = 3600; - sh_a->wf->nBlockAlign = track->coded_framesize; - track->audio_buf = malloc(track->sub_packet_h * track->audiopk_size); - track->audio_timestamp = malloc(track->sub_packet_h * sizeof(float)); - break; - } + sh_a->wf->nAvgBytesPerSec = 3600; + sh_a->wf->nBlockAlign = track->coded_framesize; + track->audio_buf = + malloc(track->sub_packet_h * track->audiopk_size); + track->audio_timestamp = + malloc(track->sub_packet_h * sizeof(float)); + break; + } - track->realmedia = 1; - } - else if (!strcmp(track->codec_id, MKV_A_FLAC) || - (track->a_formattag == 0xf1ac)) - { - unsigned char *ptr; - int size; - free(sh_a->wf); - sh_a->wf = NULL; + track->realmedia = 1; + } else if (!strcmp(track->codec_id, MKV_A_FLAC) + || (track->a_formattag == 0xf1ac)) { + unsigned char *ptr; + int size; + free(sh_a->wf); + sh_a->wf = NULL; - if (track->a_formattag == mmioFOURCC('f', 'L', 'a', 'C')) - { - ptr = track->private_data; - size = track->private_size; + if (track->a_formattag == mmioFOURCC('f', 'L', 'a', 'C')) { + ptr = track->private_data; + size = track->private_size; + } else { + sh_a->format = mmioFOURCC('f', 'L', 'a', 'C'); + ptr = track->private_data + sizeof(WAVEFORMATEX); + size = track->private_size - sizeof(WAVEFORMATEX); } - else - { - sh_a->format = mmioFOURCC('f', 'L', 'a', 'C'); - ptr = track->private_data + sizeof (WAVEFORMATEX); - size = track->private_size - sizeof (WAVEFORMATEX); + if (size < 4 || ptr[0] != 'f' || ptr[1] != 'L' || ptr[2] != 'a' + || ptr[3] != 'C') { + dp = new_demux_packet(4); + memcpy(dp->buffer, "fLaC", 4); + } else { + dp = new_demux_packet(size); + memcpy(dp->buffer, ptr, size); } - if (size < 4 || ptr[0] != 'f' || ptr[1] != 'L' || - ptr[2] != 'a' || ptr[3] != 'C') - { - dp = new_demux_packet (4); - memcpy (dp->buffer, "fLaC", 4); - } - else - { - dp = new_demux_packet (size); - memcpy (dp->buffer, ptr, size); - } - dp->pts = 0; - dp->flags = 0; - ds_add_packet (demuxer->audio, dp); - } - else if (track->a_formattag == mmioFOURCC('W', 'V', 'P', 'K') || - track->a_formattag == mmioFOURCC('T', 'R', 'H', 'D')) - { /* do nothing, still works */ } - else if (!track->ms_compat || (track->private_size < sizeof(WAVEFORMATEX))) - { - free_sh_audio(demuxer, track->tnum); - return 1; + dp->pts = 0; + dp->flags = 0; + ds_add_packet(demuxer->audio, dp); + } else if (track->a_formattag == mmioFOURCC('W', 'V', 'P', 'K') || + track->a_formattag == mmioFOURCC('T', 'R', 'H', 'D')) { + /* do nothing, still works */ + } else if (!track->ms_compat + || (track->private_size < sizeof(WAVEFORMATEX))) { + free_sh_audio(demuxer, track->tnum); + return 1; } - return 0; + return 0; } -static int -demux_mkv_open_sub (demuxer_t *demuxer, mkv_track_t *track, int sid) +static int demux_mkv_open_sub(demuxer_t *demuxer, mkv_track_t *track, + int sid) { - if (track->subtitle_type != MATROSKA_SUBTYPE_UNKNOWN) - { - int size, m; - uint8_t *buffer; - sh_sub_t *sh = new_sh_sub_sid(demuxer, track->tnum, sid); - track->sh_sub = sh; - sh->type = 't'; - if (track->subtitle_type == MATROSKA_SUBTYPE_VOBSUB) - sh->type = 'v'; - if (track->subtitle_type == MATROSKA_SUBTYPE_SSA) - sh->type = 'a'; - size = track->private_size; - m = demux_mkv_decode (track,track->private_data,&buffer,&size,2); - if (buffer && m) - { - free (track->private_data); - track->private_data = buffer; - track->private_size = size; + if (track->subtitle_type != MATROSKA_SUBTYPE_UNKNOWN) { + int size, m; + uint8_t *buffer; + sh_sub_t *sh = new_sh_sub_sid(demuxer, track->tnum, sid); + track->sh_sub = sh; + sh->type = 't'; + if (track->subtitle_type == MATROSKA_SUBTYPE_VOBSUB) + sh->type = 'v'; + if (track->subtitle_type == MATROSKA_SUBTYPE_SSA) + sh->type = 'a'; + size = track->private_size; + m = demux_mkv_decode(track, track->private_data, &buffer, &size, 2); + if (buffer && m) { + free(track->private_data); + track->private_data = buffer; + track->private_size = size; } - sh->extradata=malloc(track->private_size); - memcpy (sh->extradata, track->private_data, - track->private_size); - sh->extradata_len = track->private_size; - if (track->language && (strcmp(track->language, "und") != 0)) - sh->lang = strdup(track->language); - sh->default_track = track->default_track; - } - else - { - mp_msg (MSGT_DEMUX, MSGL_ERR, MSGTR_MPDEMUX_MKV_SubtitleTypeNotSupported, - track->codec_id); - return 1; + sh->extradata = malloc(track->private_size); + memcpy(sh->extradata, track->private_data, track->private_size); + sh->extradata_len = track->private_size; + if (track->language && (strcmp(track->language, "und") != 0)) + sh->lang = strdup(track->language); + sh->default_track = track->default_track; + } else { + mp_msg(MSGT_DEMUX, MSGL_ERR, + MSGTR_MPDEMUX_MKV_SubtitleTypeNotSupported, track->codec_id); + return 1; } - return 0; + return 0; } -static int -demux_mkv_open (demuxer_t *demuxer) +static int demux_mkv_open(demuxer_t *demuxer) { - stream_t *s = demuxer->stream; - mkv_demuxer_t *mkv_d; - mkv_track_t *track; - int i, version, cont = 0; - char *str; + stream_t *s = demuxer->stream; + mkv_demuxer_t *mkv_d; + mkv_track_t *track; + int i, version, cont = 0; + char *str; - stream_seek(s, s->start_pos); - str = ebml_read_header (s, &version); - if (str == NULL || strcmp (str, "matroska") || version > 2) - { - mp_msg (MSGT_DEMUX, MSGL_DBG2, "[mkv] no head found\n"); - return 0; + stream_seek(s, s->start_pos); + str = ebml_read_header(s, &version); + if (str == NULL || strcmp(str, "matroska") || version > 2) { + mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] no head found\n"); + return 0; } - free (str); + free(str); - mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] Found the head...\n"); + mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] Found the head...\n"); - if (ebml_read_id (s, NULL) != MATROSKA_ID_SEGMENT) - { - mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] but no segment :(\n"); - return 0; + if (ebml_read_id(s, NULL) != MATROSKA_ID_SEGMENT) { + mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] but no segment :(\n"); + return 0; } - ebml_read_length (s, NULL); /* return bytes number until EOF */ + ebml_read_length(s, NULL); /* return bytes number until EOF */ - mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] + a segment...\n"); + mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] + a segment...\n"); - mkv_d = calloc (1, sizeof (mkv_demuxer_t)); - demuxer->priv = mkv_d; - mkv_d->tc_scale = 1000000; - mkv_d->segment_start = stream_tell (s); - mkv_d->parsed_cues = malloc (sizeof (off_t)); - mkv_d->parsed_seekhead = malloc (sizeof (off_t)); + mkv_d = calloc(1, sizeof(mkv_demuxer_t)); + demuxer->priv = mkv_d; + mkv_d->tc_scale = 1000000; + mkv_d->segment_start = stream_tell(s); + mkv_d->parsed_cues = malloc(sizeof(off_t)); + mkv_d->parsed_seekhead = malloc(sizeof(off_t)); - while (!cont) - { - switch (ebml_read_id (s, NULL)) - { + while (!cont) { + switch (ebml_read_id(s, NULL)) { case MATROSKA_ID_INFO: - mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] |+ segment information...\n"); - cont = demux_mkv_read_info (demuxer); - break; + mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] |+ segment information...\n"); + cont = demux_mkv_read_info(demuxer); + break; case MATROSKA_ID_TRACKS: - mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] |+ segment tracks...\n"); - cont = demux_mkv_read_tracks (demuxer); - break; + mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] |+ segment tracks...\n"); + cont = demux_mkv_read_tracks(demuxer); + break; case MATROSKA_ID_CUES: - cont = demux_mkv_read_cues (demuxer); - break; + cont = demux_mkv_read_cues(demuxer); + break; case MATROSKA_ID_TAGS: - cont = demux_mkv_read_tags (demuxer); - break; + cont = demux_mkv_read_tags(demuxer); + break; case MATROSKA_ID_SEEKHEAD: - cont = demux_mkv_read_seekhead (demuxer); - break; + cont = demux_mkv_read_seekhead(demuxer); + break; case MATROSKA_ID_CHAPTERS: - cont = demux_mkv_read_chapters (demuxer); - break; + cont = demux_mkv_read_chapters(demuxer); + break; case MATROSKA_ID_ATTACHMENTS: - cont = demux_mkv_read_attachments (demuxer); - break; + cont = demux_mkv_read_attachments(demuxer); + break; case MATROSKA_ID_CLUSTER: - { + { int p, l; - mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] |+ found cluster, headers are " - "parsed completely :)\n"); + mp_msg(MSGT_DEMUX, MSGL_V, + "[mkv] |+ found cluster, headers are " + "parsed completely :)\n"); /* get the first cluster timecode */ p = stream_tell(s); - l = ebml_read_length (s, NULL); - while (ebml_read_id (s, NULL) != MATROSKA_ID_CLUSTERTIMECODE) - { - ebml_read_skip (s, NULL); - if (stream_tell (s) >= p + l) - break; - } - if (stream_tell (s) < p + l) - { - uint64_t num = ebml_read_uint (s, NULL); + l = ebml_read_length(s, NULL); + while (ebml_read_id(s, NULL) != MATROSKA_ID_CLUSTERTIMECODE) { + ebml_read_skip(s, NULL); + if (stream_tell(s) >= p + l) + break; + } + if (stream_tell(s) < p + l) { + uint64_t num = ebml_read_uint(s, NULL); if (num == EBML_UINT_INVALID) - return 0; + return 0; mkv_d->first_tc = num * mkv_d->tc_scale / 1000000.0; mkv_d->has_first_tc = 1; - } - stream_seek (s, p - 4); + } + stream_seek(s, p - 4); cont = 1; break; - } + } default: - cont = 1; + cont = 1; case EBML_ID_VOID: - ebml_read_skip (s, NULL); - break; + ebml_read_skip(s, NULL); + break; } } - display_create_tracks (demuxer); + display_create_tracks(demuxer); - /* select video track */ - track = NULL; - if (demuxer->video->id == -1) /* automatically select a video track */ - { - /* search for a video track that has the 'default' flag set */ - for (i=0; inum_tracks; i++) - if (mkv_d->tracks[i]->type == MATROSKA_TRACK_VIDEO - && mkv_d->tracks[i]->default_track) - { - track = mkv_d->tracks[i]; - break; - } + /* select video track */ + track = NULL; + if (demuxer->video->id == -1) { /* automatically select a video track */ + /* search for a video track that has the 'default' flag set */ + for (i = 0; i < mkv_d->num_tracks; i++) + if (mkv_d->tracks[i]->type == MATROSKA_TRACK_VIDEO + && mkv_d->tracks[i]->default_track) { + track = mkv_d->tracks[i]; + break; + } - if (track == NULL) + if (track == NULL) + /* no track has the 'default' flag set */ + /* let's take the first video track */ + for (i = 0; i < mkv_d->num_tracks; i++) + if (mkv_d->tracks[i]->type == MATROSKA_TRACK_VIDEO) { + track = mkv_d->tracks[i]; + break; + } + } else if (demuxer->video->id != -2) /* -2 = no video at all */ + track = demux_mkv_find_track_by_num(mkv_d, demuxer->video->id, + MATROSKA_TRACK_VIDEO); + + if (track && demuxer->v_streams[track->tnum]) { + mp_msg(MSGT_DEMUX, MSGL_INFO, MSGTR_MPDEMUX_MKV_WillPlayVideoTrack, + track->tnum); + demuxer->video->id = track->tnum; + demuxer->video->sh = demuxer->v_streams[track->tnum]; + } else { + mp_msg(MSGT_DEMUX, MSGL_INFO, MSGTR_MPDEMUX_MKV_NoVideoTrackFound); + demuxer->video->id = -2; + } + + /* select audio track */ + track = NULL; + if (track == NULL) + /* search for an audio track that has the 'default' flag set */ + for (i = 0; i < mkv_d->num_tracks; i++) + if (mkv_d->tracks[i]->type == MATROSKA_TRACK_AUDIO + && mkv_d->tracks[i]->default_track) { + track = mkv_d->tracks[i]; + break; + } + + if (track == NULL) /* no track has the 'default' flag set */ - /* let's take the first video track */ - for (i=0; inum_tracks; i++) - if (mkv_d->tracks[i]->type == MATROSKA_TRACK_VIDEO) - { - track = mkv_d->tracks[i]; - break; + /* let's take the first audio track */ + for (i = 0; i < mkv_d->num_tracks; i++) + if (mkv_d->tracks[i]->type == MATROSKA_TRACK_AUDIO) { + track = mkv_d->tracks[i]; + break; } - } - else if (demuxer->video->id != -2) /* -2 = no video at all */ - track = demux_mkv_find_track_by_num (mkv_d, demuxer->video->id, - MATROSKA_TRACK_VIDEO); - if (track && demuxer->v_streams[track->tnum]) - { - mp_msg (MSGT_DEMUX, MSGL_INFO, - MSGTR_MPDEMUX_MKV_WillPlayVideoTrack, track->tnum); - demuxer->video->id = track->tnum; - demuxer->video->sh = demuxer->v_streams[track->tnum]; - } - else - { - mp_msg (MSGT_DEMUX, MSGL_INFO, MSGTR_MPDEMUX_MKV_NoVideoTrackFound); - demuxer->video->id = -2; + if (track && demuxer->a_streams[track->tnum]) { + demuxer->audio->id = track->tnum; + demuxer->audio->sh = demuxer->a_streams[track->tnum]; + } else { + mp_msg(MSGT_DEMUX, MSGL_INFO, MSGTR_MPDEMUX_MKV_NoAudioTrackFound); + demuxer->audio->id = -2; } - /* select audio track */ - track = NULL; - if (track == NULL) - /* search for an audio track that has the 'default' flag set */ - for (i=0; i < mkv_d->num_tracks; i++) - if (mkv_d->tracks[i]->type == MATROSKA_TRACK_AUDIO - && mkv_d->tracks[i]->default_track) - { - track = mkv_d->tracks[i]; - break; + + if (demuxer->audio->id != -2) + for (i = 0; i < mkv_d->num_tracks; i++) { + if (mkv_d->tracks[i]->type != MATROSKA_TRACK_AUDIO) + continue; + if (demuxer->a_streams[track->tnum]) { + mkv_d->last_aid++; + if (mkv_d->last_aid == MAX_A_STREAMS) + break; + } } - if (track == NULL) - /* no track has the 'default' flag set */ - /* let's take the first audio track */ - for (i=0; i < mkv_d->num_tracks; i++) - if (mkv_d->tracks[i]->type == MATROSKA_TRACK_AUDIO) - { - track = mkv_d->tracks[i]; - break; + if (demuxer->chapters) { + for (i = 0; i < (int) demuxer->num_chapters; i++) { + demuxer->chapters[i].start -= mkv_d->first_tc; + demuxer->chapters[i].end -= mkv_d->first_tc; } - - if (track && demuxer->a_streams[track->tnum]) - { - demuxer->audio->id = track->tnum; - demuxer->audio->sh = demuxer->a_streams[track->tnum]; - } - else - { - mp_msg (MSGT_DEMUX, MSGL_INFO, MSGTR_MPDEMUX_MKV_NoAudioTrackFound); - demuxer->audio->id = -2; - } - - - if(demuxer->audio->id != -2) - for (i=0; i < mkv_d->num_tracks; i++) - { - if(mkv_d->tracks[i]->type != MATROSKA_TRACK_AUDIO) - continue; - if(demuxer->a_streams[track->tnum]) - { - mkv_d->last_aid++; - if(mkv_d->last_aid == MAX_A_STREAMS) - break; + if (dvd_last_chapter > 0 && dvd_last_chapter <= demuxer->num_chapters) { + if (demuxer->chapters[dvd_last_chapter - 1].end != 0) + mkv_d->stop_timecode = + demuxer->chapters[dvd_last_chapter - 1].end; + else if (dvd_last_chapter + 1 <= demuxer->num_chapters) + mkv_d->stop_timecode = + demuxer->chapters[dvd_last_chapter].start; } } - if (demuxer->chapters) - { - for (i=0; i < (int)demuxer->num_chapters; i++) - { - demuxer->chapters[i].start -= mkv_d->first_tc; - demuxer->chapters[i].end -= mkv_d->first_tc; - } - if (dvd_last_chapter > 0 && dvd_last_chapter <= demuxer->num_chapters) - { - if (demuxer->chapters[dvd_last_chapter-1].end != 0) - mkv_d->stop_timecode = demuxer->chapters[dvd_last_chapter-1].end; - else if (dvd_last_chapter + 1 <= demuxer->num_chapters) - mkv_d->stop_timecode = demuxer->chapters[dvd_last_chapter].start; - } + if (s->end_pos == 0 || (mkv_d->indexes == NULL && index_mode < 0)) + demuxer->seekable = 0; + else { + demuxer->movi_start = s->start_pos; + demuxer->movi_end = s->end_pos; + demuxer->seekable = 1; } - if (s->end_pos == 0 || (mkv_d->indexes == NULL && index_mode < 0)) - demuxer->seekable = 0; - else - { - demuxer->movi_start = s->start_pos; - demuxer->movi_end = s->end_pos; - demuxer->seekable = 1; - } - - return DEMUXER_TYPE_MATROSKA; + return DEMUXER_TYPE_MATROSKA; } -static void -demux_close_mkv (demuxer_t *demuxer) +static void demux_close_mkv(demuxer_t *demuxer) { - mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv; + mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv; - if (mkv_d) - { - int i; - free_cached_dps (demuxer); - if (mkv_d->tracks) - { - for (i=0; inum_tracks; i++) - demux_mkv_free_trackentry(mkv_d->tracks[i]); - free (mkv_d->tracks); + if (mkv_d) { + int i; + free_cached_dps(demuxer); + if (mkv_d->tracks) { + for (i = 0; i < mkv_d->num_tracks; i++) + demux_mkv_free_trackentry(mkv_d->tracks[i]); + free(mkv_d->tracks); } - free (mkv_d->indexes); - free (mkv_d->cluster_positions); - free (mkv_d->parsed_cues); - free (mkv_d->parsed_seekhead); - free (mkv_d); + free(mkv_d->indexes); + free(mkv_d->cluster_positions); + free(mkv_d->parsed_cues); + free(mkv_d->parsed_seekhead); + free(mkv_d); } } -static int -demux_mkv_read_block_lacing (uint8_t *buffer, uint64_t *size, - uint8_t *laces, uint32_t **all_lace_sizes) +static int demux_mkv_read_block_lacing(uint8_t *buffer, uint64_t *size, + uint8_t *laces, + uint32_t **all_lace_sizes) { - uint32_t total = 0, *lace_size; - uint8_t flags; - int i; + uint32_t total = 0, *lace_size; + uint8_t flags; + int i; - *all_lace_sizes = NULL; - lace_size = NULL; - /* lacing flags */ - flags = *buffer++; - (*size)--; + *all_lace_sizes = NULL; + lace_size = NULL; + /* lacing flags */ + flags = *buffer++; + (*size)--; - switch ((flags & 0x06) >> 1) - { - case 0: /* no lacing */ - *laces = 1; - lace_size = calloc(*laces, sizeof(uint32_t)); - lace_size[0] = *size; - break; + switch ((flags & 0x06) >> 1) { + case 0: /* no lacing */ + *laces = 1; + lace_size = calloc(*laces, sizeof(uint32_t)); + lace_size[0] = *size; + break; - case 1: /* xiph lacing */ - case 2: /* fixed-size lacing */ - case 3: /* EBML lacing */ - *laces = *buffer++; - (*size)--; - (*laces)++; - lace_size = calloc(*laces, sizeof(uint32_t)); + case 1: /* xiph lacing */ + case 2: /* fixed-size lacing */ + case 3: /* EBML lacing */ + *laces = *buffer++; + (*size)--; + (*laces)++; + lace_size = calloc(*laces, sizeof(uint32_t)); - switch ((flags & 0x06) >> 1) - { - case 1: /* xiph lacing */ - for (i=0; i < *laces-1; i++) - { - lace_size[i] = 0; - do - { - lace_size[i] += *buffer; - (*size)--; + switch ((flags & 0x06) >> 1) { + case 1: /* xiph lacing */ + for (i = 0; i < *laces - 1; i++) { + lace_size[i] = 0; + do { + lace_size[i] += *buffer; + (*size)--; } while (*buffer++ == 0xFF); - total += lace_size[i]; + total += lace_size[i]; } - lace_size[i] = *size - total; - break; + lace_size[i] = *size - total; + break; - case 2: /* fixed-size lacing */ - for (i=0; i < *laces; i++) - lace_size[i] = *size / *laces; - break; + case 2: /* fixed-size lacing */ + for (i = 0; i < *laces; i++) + lace_size[i] = *size / *laces; + break; - case 3: /* EBML lacing */ - { + case 3: /* EBML lacing */ + { int l; - uint64_t num = ebml_read_vlen_uint (buffer, &l); + uint64_t num = ebml_read_vlen_uint(buffer, &l); if (num == EBML_UINT_INVALID) { - free(lace_size); - return 1; + free(lace_size); + return 1; } buffer += l; *size -= l; total = lace_size[0] = num; - for (i=1; i < *laces-1; i++) - { + for (i = 1; i < *laces - 1; i++) { int64_t snum; - snum = ebml_read_vlen_int (buffer, &l); + snum = ebml_read_vlen_int(buffer, &l); if (snum == EBML_INT_INVALID) { - free(lace_size); - return 1; + free(lace_size); + return 1; } buffer += l; *size -= l; - lace_size[i] = lace_size[i-1] + snum; + lace_size[i] = lace_size[i - 1] + snum; total += lace_size[i]; - } + } lace_size[i] = *size - total; break; - } } - break; + } + break; } - *all_lace_sizes = lace_size; - return 0; + *all_lace_sizes = lace_size; + return 0; } -static void -handle_subtitles(demuxer_t *demuxer, mkv_track_t *track, char *block, - int64_t size, uint64_t block_duration, uint64_t timecode) +static void handle_subtitles(demuxer_t *demuxer, mkv_track_t *track, + char *block, int64_t size, + uint64_t block_duration, uint64_t timecode) { - demux_packet_t *dp; + demux_packet_t *dp; - if (block_duration == 0) - { - mp_msg (MSGT_DEMUX, MSGL_WARN, - MSGTR_MPDEMUX_MKV_NoBlockDurationForSubtitleTrackFound); - return; + if (block_duration == 0) { + mp_msg(MSGT_DEMUX, MSGL_WARN, + MSGTR_MPDEMUX_MKV_NoBlockDurationForSubtitleTrackFound); + return; } - sub_utf8 = 1; - dp = new_demux_packet(size); - memcpy(dp->buffer, block, size); - dp->pts = timecode / 1000.0f; - dp->endpts = (timecode + block_duration) / 1000.0f; - ds_add_packet(demuxer->sub, dp); + sub_utf8 = 1; + dp = new_demux_packet(size); + memcpy(dp->buffer, block, size); + dp->pts = timecode / 1000.0f; + dp->endpts = (timecode + block_duration) / 1000.0f; + ds_add_packet(demuxer->sub, dp); } -static void -handle_realvideo (demuxer_t *demuxer, mkv_track_t *track, uint8_t *buffer, - uint32_t size, int block_bref) +static void handle_realvideo(demuxer_t *demuxer, mkv_track_t *track, + uint8_t *buffer, uint32_t size, int block_bref) { - mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv; - demux_packet_t *dp; - uint32_t timestamp = mkv_d->last_pts * 1000; + mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv; + demux_packet_t *dp; + uint32_t timestamp = mkv_d->last_pts * 1000; - dp = new_demux_packet (size); - memcpy (dp->buffer, buffer, size); + dp = new_demux_packet(size); + memcpy(dp->buffer, buffer, size); - if (mkv_d->v_skip_to_keyframe) - { - dp->pts = mkv_d->last_pts; - track->rv_kf_base = 0; - track->rv_kf_pts = timestamp; - } - else - dp->pts = real_fix_timestamp (dp->buffer, timestamp, - ((sh_video_t*)demuxer->video->sh)->bih->biCompression, - &track->rv_kf_base, &track->rv_kf_pts, NULL); - dp->pos = demuxer->filepos; - dp->flags = block_bref ? 0 : 0x10; + if (mkv_d->v_skip_to_keyframe) { + dp->pts = mkv_d->last_pts; + track->rv_kf_base = 0; + track->rv_kf_pts = timestamp; + } else + dp->pts = + real_fix_timestamp(dp->buffer, timestamp, + ((sh_video_t *) demuxer->video->sh)->bih-> + biCompression, &track->rv_kf_base, + &track->rv_kf_pts, NULL); + dp->pos = demuxer->filepos; + dp->flags = block_bref ? 0 : 0x10; - ds_add_packet(demuxer->video, dp); + ds_add_packet(demuxer->video, dp); } -static void -handle_realaudio (demuxer_t *demuxer, mkv_track_t *track, uint8_t *buffer, - uint32_t size, int block_bref) +static void handle_realaudio(demuxer_t *demuxer, mkv_track_t *track, + uint8_t *buffer, uint32_t size, int block_bref) { - mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv; - int sps = track->sub_packet_size; - int sph = track->sub_packet_h; - int cfs = track->coded_framesize; - int w = track->audiopk_size; - int spc = track->sub_packet_cnt; - demux_packet_t *dp; - int x; + mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv; + int sps = track->sub_packet_size; + int sph = track->sub_packet_h; + int cfs = track->coded_framesize; + int w = track->audiopk_size; + int spc = track->sub_packet_cnt; + demux_packet_t *dp; + int x; - if ((track->a_formattag == mmioFOURCC('2', '8', '_', '8')) || - (track->a_formattag == mmioFOURCC('c', 'o', 'o', 'k')) || - (track->a_formattag == mmioFOURCC('a', 't', 'r', 'c')) || - (track->a_formattag == mmioFOURCC('s', 'i', 'p', 'r'))) - { + if ((track->a_formattag == mmioFOURCC('2', '8', '_', '8')) + || (track->a_formattag == mmioFOURCC('c', 'o', 'o', 'k')) + || (track->a_formattag == mmioFOURCC('a', 't', 'r', 'c')) + || (track->a_formattag == mmioFOURCC('s', 'i', 'p', 'r'))) { // if(!block_bref) // spc = track->sub_packet_cnt = 0; - switch (track->a_formattag) { + switch (track->a_formattag) { case mmioFOURCC('2', '8', '_', '8'): - for (x = 0; x < sph / 2; x++) - memcpy(track->audio_buf + x * 2 * w + spc * cfs, buffer + cfs * x, cfs); - break; + for (x = 0; x < sph / 2; x++) + memcpy(track->audio_buf + x * 2 * w + spc * cfs, + buffer + cfs * x, cfs); + break; case mmioFOURCC('c', 'o', 'o', 'k'): case mmioFOURCC('a', 't', 'r', 'c'): - for (x = 0; x < w / sps; x++) - memcpy(track->audio_buf + sps * (sph * x + ((sph + 1) / 2) * (spc & 1) + (spc >> 1)), buffer + sps * x, sps); - break; + for (x = 0; x < w / sps; x++) + memcpy(track->audio_buf + + sps * (sph * x + ((sph + 1) / 2) * (spc & 1) + + (spc >> 1)), buffer + sps * x, sps); + break; case mmioFOURCC('s', 'i', 'p', 'r'): - memcpy(track->audio_buf + spc * w, buffer, w); - if (spc == sph - 1) - { - int n; - int bs = sph * w * 2 / 96; // nibbles per subpacket - // Perform reordering - for(n=0; n < 38; n++) - { - int j; - int i = bs * sipr_swaps[n][0]; - int o = bs * sipr_swaps[n][1]; - // swap nibbles of block 'i' with 'o' TODO: optimize - for(j = 0;j < bs; j++) - { - int x = (i & 1) ? (track->audio_buf[i >> 1] >> 4) : (track->audio_buf[i >> 1] & 0x0F); - int y = (o & 1) ? (track->audio_buf[o >> 1] >> 4) : (track->audio_buf[o >> 1] & 0x0F); - if(o & 1) - track->audio_buf[o >> 1] = (track->audio_buf[o >> 1] & 0x0F) | (x << 4); - else - track->audio_buf[o >> 1] = (track->audio_buf[o >> 1] & 0xF0) | x; - if(i & 1) - track->audio_buf[i >> 1] = (track->audio_buf[i >> 1] & 0x0F) | (y << 4); - else - track->audio_buf[i >> 1] = (track->audio_buf[i >> 1] & 0xF0) | y; - ++i; ++o; + memcpy(track->audio_buf + spc * w, buffer, w); + if (spc == sph - 1) { + int n; + int bs = sph * w * 2 / 96; // nibbles per subpacket + // Perform reordering + for (n = 0; n < 38; n++) { + int j; + int i = bs * sipr_swaps[n][0]; + int o = bs * sipr_swaps[n][1]; + // swap nibbles of block 'i' with 'o' TODO: optimize + for (j = 0; j < bs; j++) { + int x = (i & 1) ? + (track->audio_buf[i >> 1] >> 4) : + (track->audio_buf[i >> 1] & 0x0F); + int y = (o & 1) ? + (track->audio_buf[o >> 1] >> 4) : + (track->audio_buf[o >> 1] & 0x0F); + if (o & 1) + track->audio_buf[o >> 1] = + (track->audio_buf[o >> 1] & 0x0F) | (x << 4); + else + track->audio_buf[o >> 1] = + (track->audio_buf[o >> 1] & 0xF0) | x; + if (i & 1) + track->audio_buf[i >> 1] = + (track->audio_buf[i >> 1] & 0x0F) | (y << 4); + else + track->audio_buf[i >> 1] = + (track->audio_buf[i >> 1] & 0xF0) | y; + ++i; + ++o; } } } - break; - } - track->audio_timestamp[track->sub_packet_cnt] = (track->ra_pts == mkv_d->last_pts) ? 0 : (mkv_d->last_pts); - track->ra_pts = mkv_d->last_pts; - if (track->sub_packet_cnt == 0) - track->audio_filepos = demuxer->filepos; - if (++(track->sub_packet_cnt) == sph) - { - int apk_usize = ((WAVEFORMATEX*)((sh_audio_t*)demuxer->audio->sh)->wf)->nBlockAlign; - track->sub_packet_cnt = 0; - // Release all the audio packets - for (x = 0; x < sph*w/apk_usize; x++) - { - dp = new_demux_packet(apk_usize); - memcpy(dp->buffer, track->audio_buf + x * apk_usize, apk_usize); - /* Put timestamp only on packets that correspond to original audio packets in file */ - dp->pts = (x * apk_usize % w) ? 0 : track->audio_timestamp[x * apk_usize / w]; - dp->pos = track->audio_filepos; // all equal - dp->flags = x ? 0 : 0x10; // Mark first packet as keyframe - ds_add_packet(demuxer->audio, dp); - } + break; } - } else { // Not a codec that require reordering - dp = new_demux_packet (size); - memcpy(dp->buffer, buffer, size); - if (track->ra_pts == mkv_d->last_pts && !mkv_d->a_skip_to_keyframe) - dp->pts = 0; - else - dp->pts = mkv_d->last_pts; - track->ra_pts = mkv_d->last_pts; + track->audio_timestamp[track->sub_packet_cnt] = + (track->ra_pts == mkv_d->last_pts) ? 0 : (mkv_d->last_pts); + track->ra_pts = mkv_d->last_pts; + if (track->sub_packet_cnt == 0) + track->audio_filepos = demuxer->filepos; + if (++(track->sub_packet_cnt) == sph) { + int apk_usize = + ((WAVEFORMATEX *) ((sh_audio_t *) demuxer->audio->sh)->wf)->nBlockAlign; + track->sub_packet_cnt = 0; + // Release all the audio packets + for (x = 0; x < sph * w / apk_usize; x++) { + dp = new_demux_packet(apk_usize); + memcpy(dp->buffer, track->audio_buf + x * apk_usize, + apk_usize); + /* Put timestamp only on packets that correspond to original + * audio packets in file */ + dp->pts = (x * apk_usize % w) ? 0 : + track->audio_timestamp[x * apk_usize / w]; + dp->pos = track->audio_filepos; // all equal + dp->flags = x ? 0 : 0x10; // Mark first packet as keyframe + ds_add_packet(demuxer->audio, dp); + } + } + } else { // Not a codec that require reordering + dp = new_demux_packet(size); + memcpy(dp->buffer, buffer, size); + if (track->ra_pts == mkv_d->last_pts && !mkv_d->a_skip_to_keyframe) + dp->pts = 0; + else + dp->pts = mkv_d->last_pts; + track->ra_pts = mkv_d->last_pts; - dp->pos = demuxer->filepos; - dp->flags = block_bref ? 0 : 0x10; - ds_add_packet (demuxer->audio, dp); - } + dp->pos = demuxer->filepos; + dp->flags = block_bref ? 0 : 0x10; + ds_add_packet(demuxer->audio, dp); + } } /** Reorder timecodes and add cached demux packets to the queues. @@ -2532,28 +2402,27 @@ handle_realaudio (demuxer_t *demuxer, mkv_track_t *track, uint8_t *buffer, * \param demuxer The Matroska demuxer struct for this instance. * \param track The track structure whose cache should be handled. */ -static void -flush_cached_dps (demuxer_t *demuxer, mkv_track_t *track) +static void flush_cached_dps(demuxer_t *demuxer, mkv_track_t *track) { - int i, ok; + int i, ok; - if (track->num_cached_dps == 0) - return; + if (track->num_cached_dps == 0) + return; - do { - ok = 1; - for (i = 1; i < track->num_cached_dps; i++) - if (track->cached_dps[i - 1]->pts > track->cached_dps[i]->pts) { - float tmp_pts = track->cached_dps[i - 1]->pts; - track->cached_dps[i - 1]->pts = track->cached_dps[i]->pts; - track->cached_dps[i]->pts = tmp_pts; - ok = 0; - } - } while (!ok); + do { + ok = 1; + for (i = 1; i < track->num_cached_dps; i++) + if (track->cached_dps[i - 1]->pts > track->cached_dps[i]->pts) { + float tmp_pts = track->cached_dps[i - 1]->pts; + track->cached_dps[i - 1]->pts = track->cached_dps[i]->pts; + track->cached_dps[i]->pts = tmp_pts; + ok = 0; + } + } while (!ok); - for (i = 0; i < track->num_cached_dps; i++) - ds_add_packet (demuxer->video, track->cached_dps[i]); - track->num_cached_dps = 0; + for (i = 0; i < track->num_cached_dps; i++) + ds_add_packet(demuxer->video, track->cached_dps[i]); + track->num_cached_dps = 0; } /** Cache video frames if timecodes have to be reordered. @@ -2576,574 +2445,534 @@ flush_cached_dps (demuxer_t *demuxer, mkv_track_t *track) * then the frame is either an I frame or a P frame depending on the value * of \a block_bref. Otherwise it's a B frame. */ -static void -handle_video_bframes (demuxer_t *demuxer, mkv_track_t *track, uint8_t *buffer, - uint32_t size, int block_bref, int block_fref) +static void handle_video_bframes(demuxer_t *demuxer, mkv_track_t *track, + uint8_t *buffer, uint32_t size, + int block_bref, int block_fref) { - mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv; - demux_packet_t *dp; + mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv; + demux_packet_t *dp; - dp = new_demux_packet (size); - memcpy(dp->buffer, buffer, size); - dp->pos = demuxer->filepos; - dp->pts = mkv_d->last_pts; - if ((track->num_cached_dps > 0) && (dp->pts < track->max_pts)) - block_fref = 1; - if (block_fref == 0) /* I or P frame */ - flush_cached_dps (demuxer, track); - if (block_bref != 0) /* I frame, don't cache it */ - dp->flags = 0x10; - if ((track->num_cached_dps + 1) > track->num_allocated_dps) - { - track->cached_dps = (demux_packet_t **) - realloc(track->cached_dps, (track->num_cached_dps + 10) * - sizeof(demux_packet_t *)); - track->num_allocated_dps += 10; + dp = new_demux_packet(size); + memcpy(dp->buffer, buffer, size); + dp->pos = demuxer->filepos; + dp->pts = mkv_d->last_pts; + if ((track->num_cached_dps > 0) && (dp->pts < track->max_pts)) + block_fref = 1; + if (block_fref == 0) /* I or P frame */ + flush_cached_dps(demuxer, track); + if (block_bref != 0) /* I frame, don't cache it */ + dp->flags = 0x10; + if ((track->num_cached_dps + 1) > track->num_allocated_dps) { + track->cached_dps = (demux_packet_t **) + realloc(track->cached_dps, + (track->num_cached_dps + 10) * sizeof(demux_packet_t *)); + track->num_allocated_dps += 10; } - track->cached_dps[track->num_cached_dps] = dp; - track->num_cached_dps++; - if (dp->pts > track->max_pts) - track->max_pts = dp->pts; + track->cached_dps[track->num_cached_dps] = dp; + track->num_cached_dps++; + if (dp->pts > track->max_pts) + track->max_pts = dp->pts; } -static int -handle_block (demuxer_t *demuxer, uint8_t *block, uint64_t length, - uint64_t block_duration, int64_t block_bref, int64_t block_fref, uint8_t simpleblock) +static int handle_block(demuxer_t *demuxer, uint8_t *block, uint64_t length, + uint64_t block_duration, int64_t block_bref, + int64_t block_fref, uint8_t simpleblock) { - mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv; - mkv_track_t *track = NULL; - demux_stream_t *ds = NULL; - uint64_t old_length; - int64_t tc; - uint32_t *lace_size; - uint8_t laces, flags; - int i, num, tmp, use_this_block = 1; - float current_pts; - int16_t time; + mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv; + mkv_track_t *track = NULL; + demux_stream_t *ds = NULL; + uint64_t old_length; + int64_t tc; + uint32_t *lace_size; + uint8_t laces, flags; + int i, num, tmp, use_this_block = 1; + float current_pts; + int16_t time; - /* first byte(s): track num */ - num = ebml_read_vlen_uint (block, &tmp); - block += tmp; - /* time (relative to cluster time) */ - time = block[0] << 8 | block[1]; - block += 2; - length -= tmp + 2; - old_length = length; - flags = block[0]; - if (demux_mkv_read_block_lacing (block, &length, &laces, &lace_size)) - return 0; - block += old_length - length; + /* first byte(s): track num */ + num = ebml_read_vlen_uint(block, &tmp); + block += tmp; + /* time (relative to cluster time) */ + time = block[0] << 8 | block[1]; + block += 2; + length -= tmp + 2; + old_length = length; + flags = block[0]; + if (demux_mkv_read_block_lacing(block, &length, &laces, &lace_size)) + return 0; + block += old_length - length; - tc = ((time*mkv_d->tc_scale+mkv_d->cluster_tc) /1000000.0 - mkv_d->first_tc); - if (tc < 0) - tc = 0; - if (mkv_d->stop_timecode > 0 && tc > mkv_d->stop_timecode) { - free(lace_size); - return -1; - } - current_pts = tc / 1000.0; - - for (i=0; inum_tracks; i++) - if (mkv_d->tracks[i]->tnum == num) { - track = mkv_d->tracks[i]; - break; + tc = ((time * mkv_d->tc_scale + mkv_d->cluster_tc) / 1000000.0 - + mkv_d->first_tc); + if (tc < 0) + tc = 0; + if (mkv_d->stop_timecode > 0 && tc > mkv_d->stop_timecode) { + free(lace_size); + return -1; } - if (track == NULL) - { - free(lace_size); - return 1; - } - if (num == demuxer->audio->id) - { - ds = demuxer->audio; + current_pts = tc / 1000.0; - if (mkv_d->a_skip_to_keyframe) - { - if (simpleblock) - { - if (!(flags&0x80)) /*current frame isn't a keyframe*/ - use_this_block = 0; + for (i = 0; i < mkv_d->num_tracks; i++) + if (mkv_d->tracks[i]->tnum == num) { + track = mkv_d->tracks[i]; + break; + } + if (track == NULL) { + free(lace_size); + return 1; + } + if (num == demuxer->audio->id) { + ds = demuxer->audio; + + if (mkv_d->a_skip_to_keyframe) { + if (simpleblock) { + if (!(flags & 0x80)) /*current frame isn't a keyframe */ + use_this_block = 0; + } else if (block_bref != 0) + use_this_block = 0; + } else if (mkv_d->v_skip_to_keyframe) + use_this_block = 0; + + if (track->fix_i_bps && use_this_block) { + sh_audio_t *sh = (sh_audio_t *) ds->sh; + + if (block_duration != 0) { + sh->i_bps = length * 1000 / block_duration; + track->fix_i_bps = 0; + } else if (track->qt_last_a_pts == 0.0) + track->qt_last_a_pts = current_pts; + else if (track->qt_last_a_pts != current_pts) { + sh->i_bps = length / (current_pts - track->qt_last_a_pts); + track->fix_i_bps = 0; } - else if (block_bref != 0) + } + } else if (tc < mkv_d->skip_to_timecode) + use_this_block = 0; + else if (num == demuxer->video->id) { + ds = demuxer->video; + if (mkv_d->v_skip_to_keyframe) { + if (simpleblock) { + if (!(flags & 0x80)) /*current frame isn't a keyframe */ + use_this_block = 0; + } else if (block_bref != 0 || block_fref != 0) + use_this_block = 0; + } + } else if (num == demuxer->sub->id) { + ds = demuxer->sub; + if (track->subtitle_type != MATROSKA_SUBTYPE_VOBSUB) { + if (!mkv_d->v_skip_to_keyframe) + handle_subtitles(demuxer, track, block, length, block_duration, + tc); use_this_block = 0; } - else if (mkv_d->v_skip_to_keyframe) + } else use_this_block = 0; - if (track->fix_i_bps && use_this_block) - { - sh_audio_t *sh = (sh_audio_t *) ds->sh; + if (use_this_block) { + mkv_d->last_pts = current_pts; + mkv_d->last_filepos = demuxer->filepos; - if (block_duration != 0) - { - sh->i_bps = length * 1000 / block_duration; - track->fix_i_bps = 0; - } - else if (track->qt_last_a_pts == 0.0) - track->qt_last_a_pts = current_pts; - else if(track->qt_last_a_pts != current_pts) - { - sh->i_bps = length / (current_pts - track->qt_last_a_pts); - track->fix_i_bps = 0; - } - } - } - else if (tc < mkv_d->skip_to_timecode) - use_this_block = 0; - else if (num == demuxer->video->id) - { - ds = demuxer->video; - if (mkv_d->v_skip_to_keyframe) - { - if (simpleblock) - { - if (!(flags&0x80)) /*current frame isn't a keyframe*/ - use_this_block = 0; - } - else if (block_bref != 0 || block_fref != 0) - use_this_block = 0; - } - } - else if (num == demuxer->sub->id) - { - ds = demuxer->sub; - if (track->subtitle_type != MATROSKA_SUBTYPE_VOBSUB) - { - if (!mkv_d->v_skip_to_keyframe) - handle_subtitles (demuxer, track, block, length, - block_duration, tc); - use_this_block = 0; - } - } - else - use_this_block = 0; - - if (use_this_block) - { - mkv_d->last_pts = current_pts; - mkv_d->last_filepos = demuxer->filepos; - - for (i=0; i < laces; i++) - { - if (ds == demuxer->video && track->realmedia) - handle_realvideo (demuxer, track, block, lace_size[i], block_bref); - else if (ds == demuxer->audio && track->realmedia) - handle_realaudio (demuxer, track, block, lace_size[i], block_bref); - else if (ds == demuxer->video && track->reorder_timecodes) - handle_video_bframes (demuxer, track, block, lace_size[i], - block_bref, block_fref); - else - { - int modified, size = lace_size[i]; - demux_packet_t *dp; - uint8_t *buffer; - modified = demux_mkv_decode (track, block, &buffer, &size, 1); - if (buffer) - { - dp = new_demux_packet (size); - memcpy (dp->buffer, buffer, size); - if (modified) - free (buffer); - dp->flags = (block_bref == 0 && block_fref == 0) ? 0x10 : 0; - /* If default_duration is 0, assume no pts value is known - * for packets after the first one (rather than all pts - * values being the same) */ - if (i == 0 || track->default_duration) - dp->pts = mkv_d->last_pts + i * track->default_duration; - ds_add_packet (ds, dp); + for (i = 0; i < laces; i++) { + if (ds == demuxer->video && track->realmedia) + handle_realvideo(demuxer, track, block, lace_size[i], + block_bref); + else if (ds == demuxer->audio && track->realmedia) + handle_realaudio(demuxer, track, block, lace_size[i], + block_bref); + else if (ds == demuxer->video && track->reorder_timecodes) + handle_video_bframes(demuxer, track, block, lace_size[i], + block_bref, block_fref); + else { + int modified, size = lace_size[i]; + demux_packet_t *dp; + uint8_t *buffer; + modified = demux_mkv_decode(track, block, &buffer, &size, 1); + if (buffer) { + dp = new_demux_packet(size); + memcpy(dp->buffer, buffer, size); + if (modified) + free(buffer); + dp->flags = (block_bref == 0 + && block_fref == 0) ? 0x10 : 0; + /* If default_duration is 0, assume no pts value is known + * for packets after the first one (rather than all pts + * values being the same) */ + if (i == 0 || track->default_duration) + dp->pts = + mkv_d->last_pts + i * track->default_duration; + ds_add_packet(ds, dp); } } - block += lace_size[i]; + block += lace_size[i]; } - if (ds == demuxer->video) - { - mkv_d->v_skip_to_keyframe = 0; - mkv_d->skip_to_timecode = 0; - } - else if (ds == demuxer->audio) - mkv_d->a_skip_to_keyframe = 0; + if (ds == demuxer->video) { + mkv_d->v_skip_to_keyframe = 0; + mkv_d->skip_to_timecode = 0; + } else if (ds == demuxer->audio) + mkv_d->a_skip_to_keyframe = 0; - free(lace_size); - return 1; + free(lace_size); + return 1; } - free(lace_size); - return 0; + free(lace_size); + return 0; } -static int -demux_mkv_fill_buffer (demuxer_t *demuxer, demux_stream_t *ds) +static int demux_mkv_fill_buffer(demuxer_t *demuxer, demux_stream_t *ds) { - mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv; - stream_t *s = demuxer->stream; - uint64_t l; - int il, tmp; + mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv; + stream_t *s = demuxer->stream; + uint64_t l; + int il, tmp; - while (1) - { - while (mkv_d->cluster_size > 0) - { - uint64_t block_duration = 0, block_length = 0; - int64_t block_bref = 0, block_fref = 0; - uint8_t *block = NULL; + while (1) { + while (mkv_d->cluster_size > 0) { + uint64_t block_duration = 0, block_length = 0; + int64_t block_bref = 0, block_fref = 0; + uint8_t *block = NULL; - while (mkv_d->blockgroup_size > 0) - { - switch (ebml_read_id (s, &il)) - { + while (mkv_d->blockgroup_size > 0) { + switch (ebml_read_id(s, &il)) { case MATROSKA_ID_BLOCKDURATION: - { - block_duration = ebml_read_uint (s, &l); + block_duration = ebml_read_uint(s, &l); if (block_duration == EBML_UINT_INVALID) { - free(block); - return 0; + free(block); + return 0; } block_duration *= mkv_d->tc_scale / 1000000.0; break; - } case MATROSKA_ID_BLOCK: - block_length = ebml_read_length (s, &tmp); - free(block); - if (block_length > SIZE_MAX - AV_LZO_INPUT_PADDING) return 0; - block = malloc (block_length + AV_LZO_INPUT_PADDING); - demuxer->filepos = stream_tell (s); - if (stream_read (s,block,block_length) != (int) block_length) - { + block_length = ebml_read_length(s, &tmp); free(block); - return 0; - } - l = tmp + block_length; - break; - - case MATROSKA_ID_REFERENCEBLOCK: - { - int64_t num = ebml_read_int (s, &l); - if (num == EBML_INT_INVALID) { - free(block); - return 0; - } - if (num <= 0) - block_bref = num; - else - block_fref = num; - break; - } - - case EBML_ID_INVALID: - free(block); - return 0; - - default: - ebml_read_skip (s, &l); - break; - } - mkv_d->blockgroup_size -= l + il; - mkv_d->cluster_size -= l + il; - } - - if (block) - { - int res = handle_block (demuxer, block, block_length, - block_duration, block_bref, block_fref, 0); - free (block); - if (res < 0) - return 0; - if (res) - return 1; - } - - if (mkv_d->cluster_size > 0) - { - switch (ebml_read_id (s, &il)) - { - case MATROSKA_ID_CLUSTERTIMECODE: - { - uint64_t num = ebml_read_uint (s, &l); - if (num == EBML_UINT_INVALID) - return 0; - if (!mkv_d->has_first_tc) - { - mkv_d->first_tc = num * mkv_d->tc_scale / 1000000.0; - mkv_d->has_first_tc = 1; - } - mkv_d->cluster_tc = num * mkv_d->tc_scale; - break; - } - - case MATROSKA_ID_BLOCKGROUP: - mkv_d->blockgroup_size = ebml_read_length (s, &tmp); - l = tmp; - break; - - case MATROSKA_ID_SIMPLEBLOCK: - { - int res; - block_length = ebml_read_length (s, &tmp); - block = malloc (block_length); - demuxer->filepos = stream_tell (s); - if (stream_read (s,block,block_length) != (int) block_length) - { - free(block); - return 0; + if (block_length > SIZE_MAX - AV_LZO_INPUT_PADDING) + return 0; + block = malloc(block_length + AV_LZO_INPUT_PADDING); + demuxer->filepos = stream_tell(s); + if (stream_read(s, block, block_length) != + (int) block_length) { + free(block); + return 0; } l = tmp + block_length; - res = handle_block (demuxer, block, block_length, - block_duration, block_bref, block_fref, 1); - free (block); - mkv_d->cluster_size -= l + il; - if (res < 0) - return 0; - else if (res) - return 1; - else mkv_d->cluster_size += l + il; break; - } + + case MATROSKA_ID_REFERENCEBLOCK: + { + int64_t num = ebml_read_int(s, &l); + if (num == EBML_INT_INVALID) { + free(block); + return 0; + } + if (num <= 0) + block_bref = num; + else + block_fref = num; + break; + } + case EBML_ID_INVALID: - return 0; + free(block); + return 0; default: - ebml_read_skip (s, &l); - break; + ebml_read_skip(s, &l); + break; } - mkv_d->cluster_size -= l + il; + mkv_d->blockgroup_size -= l + il; + mkv_d->cluster_size -= l + il; + } + + if (block) { + int res = handle_block(demuxer, block, block_length, + block_duration, block_bref, block_fref, + 0); + free(block); + if (res < 0) + return 0; + if (res) + return 1; + } + + if (mkv_d->cluster_size > 0) { + switch (ebml_read_id(s, &il)) { + case MATROSKA_ID_CLUSTERTIMECODE: + { + uint64_t num = ebml_read_uint(s, &l); + if (num == EBML_UINT_INVALID) + return 0; + if (!mkv_d->has_first_tc) { + mkv_d->first_tc = num * mkv_d->tc_scale / 1000000.0; + mkv_d->has_first_tc = 1; + } + mkv_d->cluster_tc = num * mkv_d->tc_scale; + break; + } + + case MATROSKA_ID_BLOCKGROUP: + mkv_d->blockgroup_size = ebml_read_length(s, &tmp); + l = tmp; + break; + + case MATROSKA_ID_SIMPLEBLOCK: + { + int res; + block_length = ebml_read_length(s, &tmp); + block = malloc(block_length); + demuxer->filepos = stream_tell(s); + if (stream_read(s, block, block_length) != + (int) block_length) { + free(block); + return 0; + } + l = tmp + block_length; + res = handle_block(demuxer, block, block_length, + block_duration, block_bref, + block_fref, 1); + free(block); + mkv_d->cluster_size -= l + il; + if (res < 0) + return 0; + else if (res) + return 1; + else + mkv_d->cluster_size += l + il; + break; + } + case EBML_ID_INVALID: + return 0; + + default: + ebml_read_skip(s, &l); + break; + } + mkv_d->cluster_size -= l + il; } } - if (ebml_read_id (s, &il) != MATROSKA_ID_CLUSTER) - return 0; - add_cluster_position(mkv_d, stream_tell(s)-il); - mkv_d->cluster_size = ebml_read_length (s, NULL); + if (ebml_read_id(s, &il) != MATROSKA_ID_CLUSTER) + return 0; + add_cluster_position(mkv_d, stream_tell(s) - il); + mkv_d->cluster_size = ebml_read_length(s, NULL); } - return 0; + return 0; } -static void -demux_mkv_seek (demuxer_t *demuxer, float rel_seek_secs, float audio_delay, int flags) +static void demux_mkv_seek(demuxer_t *demuxer, float rel_seek_secs, + float audio_delay, int flags) { - free_cached_dps (demuxer); - if (!(flags & SEEK_FACTOR)) /* time in secs */ - { - mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv; - stream_t *s = demuxer->stream; - int64_t target_timecode = 0, diff, min_diff=0xFFFFFFFFFFFFFFFLL; - int i; + free_cached_dps(demuxer); + if (!(flags & SEEK_FACTOR)) { /* time in secs */ + mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv; + stream_t *s = demuxer->stream; + int64_t target_timecode = 0, diff, min_diff = 0xFFFFFFFFFFFFFFFLL; + int i; - if (!(flags & SEEK_ABSOLUTE)) /* relative seek */ - target_timecode = (int64_t) (mkv_d->last_pts * 1000.0); - target_timecode += (int64_t)(rel_seek_secs * 1000.0); - if (target_timecode < 0) - target_timecode = 0; + if (!(flags & SEEK_ABSOLUTE)) /* relative seek */ + target_timecode = (int64_t) (mkv_d->last_pts * 1000.0); + target_timecode += (int64_t) (rel_seek_secs * 1000.0); + if (target_timecode < 0) + target_timecode = 0; - if (mkv_d->indexes == NULL) /* no index was found */ - { - uint64_t target_filepos, cluster_pos, max_pos; + if (mkv_d->indexes == NULL) { /* no index was found */ + uint64_t target_filepos, cluster_pos, max_pos; - target_filepos = (uint64_t) (target_timecode * mkv_d->last_filepos - / (mkv_d->last_pts * 1000.0)); + target_filepos = + (uint64_t) (target_timecode * mkv_d->last_filepos / + (mkv_d->last_pts * 1000.0)); - max_pos = mkv_d->num_cluster_pos ? mkv_d->cluster_positions[mkv_d->num_cluster_pos-1] : 0; - if (target_filepos > max_pos) - { - if ((off_t) max_pos > stream_tell (s)) - stream_seek (s, max_pos); - else - stream_seek (s, stream_tell (s) + mkv_d->cluster_size); - /* parse all the clusters upto target_filepos */ - while (!s->eof && stream_tell(s) < (off_t) target_filepos) - { - switch (ebml_read_id (s, &i)) - { + max_pos = mkv_d->num_cluster_pos ? + mkv_d->cluster_positions[mkv_d->num_cluster_pos - 1] : 0; + if (target_filepos > max_pos) { + if ((off_t) max_pos > stream_tell(s)) + stream_seek(s, max_pos); + else + stream_seek(s, stream_tell(s) + mkv_d->cluster_size); + /* parse all the clusters upto target_filepos */ + while (!s->eof && stream_tell(s) < (off_t) target_filepos) { + switch (ebml_read_id(s, &i)) { case MATROSKA_ID_CLUSTER: - add_cluster_position(mkv_d, (uint64_t) stream_tell(s)-i); - break; + add_cluster_position(mkv_d, + (uint64_t) stream_tell(s) - i); + break; case MATROSKA_ID_CUES: - demux_mkv_read_cues (demuxer); - break; + demux_mkv_read_cues(demuxer); + break; } - ebml_read_skip (s, NULL); + ebml_read_skip(s, NULL); } - if (s->eof) - stream_reset(s); + if (s->eof) + stream_reset(s); } - if (mkv_d->indexes == NULL) - { - cluster_pos = mkv_d->cluster_positions[0]; - /* Let's find the nearest cluster */ - for (i=0; i < mkv_d->num_cluster_pos; i++) - { - diff = mkv_d->cluster_positions[i] - target_filepos; - if (rel_seek_secs < 0 && diff < 0 && -diff < min_diff) - { - cluster_pos = mkv_d->cluster_positions[i]; - min_diff = -diff; - } - else if (rel_seek_secs > 0 - && (diff < 0 ? -1 * diff : diff) < min_diff) - { - cluster_pos = mkv_d->cluster_positions[i]; - min_diff = diff < 0 ? -1 * diff : diff; + if (mkv_d->indexes == NULL) { + cluster_pos = mkv_d->cluster_positions[0]; + /* Let's find the nearest cluster */ + for (i = 0; i < mkv_d->num_cluster_pos; i++) { + diff = mkv_d->cluster_positions[i] - target_filepos; + if (rel_seek_secs < 0 && diff < 0 && -diff < min_diff) { + cluster_pos = mkv_d->cluster_positions[i]; + min_diff = -diff; + } else if (rel_seek_secs > 0 + && (diff < 0 ? -1 * diff : diff) < min_diff) { + cluster_pos = mkv_d->cluster_positions[i]; + min_diff = diff < 0 ? -1 * diff : diff; } } - mkv_d->cluster_size = mkv_d->blockgroup_size = 0; - stream_seek (s, cluster_pos); + mkv_d->cluster_size = mkv_d->blockgroup_size = 0; + stream_seek(s, cluster_pos); } - } - else - { - mkv_index_t *index = NULL; - int seek_id = (demuxer->video->id < 0) ? demuxer->audio->id : demuxer->video->id; + } else { + mkv_index_t *index = NULL; + int seek_id = (demuxer->video->id < 0) ? + demuxer->audio->id : demuxer->video->id; - /* let's find the entry in the indexes with the smallest */ - /* difference to the wanted timecode. */ - for (i=0; i < mkv_d->num_indexes; i++) - if (mkv_d->indexes[i].tnum == seek_id) - { - diff = target_timecode + mkv_d->first_tc - - (int64_t) mkv_d->indexes[i].timecode * mkv_d->tc_scale / 1000000.0; + /* let's find the entry in the indexes with the smallest */ + /* difference to the wanted timecode. */ + for (i = 0; i < mkv_d->num_indexes; i++) + if (mkv_d->indexes[i].tnum == seek_id) { + diff = + target_timecode + mkv_d->first_tc - + (int64_t) mkv_d->indexes[i].timecode * + mkv_d->tc_scale / 1000000.0; - if ((flags & SEEK_ABSOLUTE || target_timecode <= mkv_d->last_pts*1000)) { - // Absolute seek or seek backward: find the last index - // position before target time - if (diff < 0 || diff >= min_diff) - continue; - } - else { - // Relative seek forward: find the first index position - // after target time. If no such index exists, find last - // position between current position and target time. - if (diff <= 0) { - if (min_diff <= 0 && diff <= min_diff) + if ((flags & SEEK_ABSOLUTE + || target_timecode <= mkv_d->last_pts * 1000)) { + // Absolute seek or seek backward: find the last index + // position before target time + if (diff < 0 || diff >= min_diff) + continue; + } else { + // Relative seek forward: find the first index position + // after target time. If no such index exists, find last + // position between current position and target time. + if (diff <= 0) { + if (min_diff <= 0 && diff <= min_diff) + continue; + } else if (diff >= + FFMIN(target_timecode - mkv_d->last_pts, + min_diff)) continue; } - else if (diff >= FFMIN(target_timecode - mkv_d->last_pts, - min_diff)) - continue; + min_diff = diff; + index = mkv_d->indexes + i; } - min_diff = diff; - index = mkv_d->indexes + i; - } - if (index) /* We've found an entry. */ - { - mkv_d->cluster_size = mkv_d->blockgroup_size = 0; - stream_seek (s, index->filepos); + if (index) { /* We've found an entry. */ + mkv_d->cluster_size = mkv_d->blockgroup_size = 0; + stream_seek(s, index->filepos); } } - if (demuxer->video->id >= 0) - mkv_d->v_skip_to_keyframe = 1; - if (rel_seek_secs > 0.0) - mkv_d->skip_to_timecode = target_timecode; - mkv_d->a_skip_to_keyframe = 1; + if (demuxer->video->id >= 0) + mkv_d->v_skip_to_keyframe = 1; + if (rel_seek_secs > 0.0) + mkv_d->skip_to_timecode = target_timecode; + mkv_d->a_skip_to_keyframe = 1; - demux_mkv_fill_buffer(demuxer, NULL); - } - else if ((demuxer->movi_end <= 0) || !(flags & SEEK_ABSOLUTE)) - mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] seek unsupported flags\n"); - else - { - mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv; - stream_t *s = demuxer->stream; - uint64_t target_filepos; - mkv_index_t *index = NULL; - int i; + demux_mkv_fill_buffer(demuxer, NULL); + } else if ((demuxer->movi_end <= 0) || !(flags & SEEK_ABSOLUTE)) + mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] seek unsupported flags\n"); + else { + mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv; + stream_t *s = demuxer->stream; + uint64_t target_filepos; + mkv_index_t *index = NULL; + int i; - if (mkv_d->indexes == NULL) /* no index was found */ - { /* I'm lazy... */ - mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] seek unsupported flags\n"); - return; + if (mkv_d->indexes == NULL) { /* no index was found *//* I'm lazy... */ + mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] seek unsupported flags\n"); + return; } - target_filepos = (uint64_t)(demuxer->movi_end * rel_seek_secs); - for (i=0; i < mkv_d->num_indexes; i++) - if (mkv_d->indexes[i].tnum == demuxer->video->id) - if ((index == NULL) || - ((mkv_d->indexes[i].filepos >= target_filepos) && - ((index->filepos < target_filepos) || - (mkv_d->indexes[i].filepos < index->filepos)))) - index = &mkv_d->indexes[i]; + target_filepos = (uint64_t) (demuxer->movi_end * rel_seek_secs); + for (i = 0; i < mkv_d->num_indexes; i++) + if (mkv_d->indexes[i].tnum == demuxer->video->id) + if ((index == NULL) + || ((mkv_d->indexes[i].filepos >= target_filepos) + && ((index->filepos < target_filepos) + || (mkv_d->indexes[i].filepos < index->filepos)))) + index = &mkv_d->indexes[i]; - if (!index) - return; + if (!index) + return; - mkv_d->cluster_size = mkv_d->blockgroup_size = 0; - stream_seek (s, index->filepos); + mkv_d->cluster_size = mkv_d->blockgroup_size = 0; + stream_seek(s, index->filepos); - if (demuxer->video->id >= 0) - mkv_d->v_skip_to_keyframe = 1; - mkv_d->skip_to_timecode = index->timecode; - mkv_d->a_skip_to_keyframe = 1; + if (demuxer->video->id >= 0) + mkv_d->v_skip_to_keyframe = 1; + mkv_d->skip_to_timecode = index->timecode; + mkv_d->a_skip_to_keyframe = 1; - demux_mkv_fill_buffer(demuxer, NULL); + demux_mkv_fill_buffer(demuxer, NULL); } } -static int -demux_mkv_control (demuxer_t *demuxer, int cmd, void *arg) +static int demux_mkv_control(demuxer_t *demuxer, int cmd, void *arg) { - mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv; + mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv; - switch (cmd) - { + switch (cmd) { case DEMUXER_CTRL_CORRECT_PTS: - return DEMUXER_CTRL_OK; + return DEMUXER_CTRL_OK; case DEMUXER_CTRL_GET_TIME_LENGTH: - if (mkv_d->duration == 0) - return DEMUXER_CTRL_DONTKNOW; + if (mkv_d->duration == 0) + return DEMUXER_CTRL_DONTKNOW; - *((double *)arg) = (double)mkv_d->duration; - return DEMUXER_CTRL_OK; + *((double *) arg) = (double) mkv_d->duration; + return DEMUXER_CTRL_OK; case DEMUXER_CTRL_GET_PERCENT_POS: - if (mkv_d->duration == 0) - { + if (mkv_d->duration == 0) { return DEMUXER_CTRL_DONTKNOW; } - *((int *) arg) = (int) (100 * mkv_d->last_pts / mkv_d->duration); - return DEMUXER_CTRL_OK; + *((int *) arg) = (int) (100 * mkv_d->last_pts / mkv_d->duration); + return DEMUXER_CTRL_OK; case DEMUXER_CTRL_SWITCH_AUDIO: - if (demuxer->audio && demuxer->audio->sh) { - sh_audio_t *sh = demuxer->a_streams[demuxer->audio->id]; - int aid = *(int*)arg; - if (aid < 0) - aid = (sh->aid + 1) % mkv_d->last_aid; - if (aid != sh->aid) { - mkv_track_t *track = demux_mkv_find_track_by_num (mkv_d, aid, MATROSKA_TRACK_AUDIO); - if (track) { - demuxer->audio->id = track->tnum; - sh = demuxer->a_streams[demuxer->audio->id]; - ds_free_packs(demuxer->audio); - } - } - *(int*)arg = sh->aid; - } else - *(int*)arg = -2; - return DEMUXER_CTRL_OK; + if (demuxer->audio && demuxer->audio->sh) { + sh_audio_t *sh = demuxer->a_streams[demuxer->audio->id]; + int aid = *(int *) arg; + if (aid < 0) + aid = (sh->aid + 1) % mkv_d->last_aid; + if (aid != sh->aid) { + mkv_track_t *track = + demux_mkv_find_track_by_num(mkv_d, aid, + MATROSKA_TRACK_AUDIO); + if (track) { + demuxer->audio->id = track->tnum; + sh = demuxer->a_streams[demuxer->audio->id]; + ds_free_packs(demuxer->audio); + } + } + *(int *) arg = sh->aid; + } else + *(int *) arg = -2; + return DEMUXER_CTRL_OK; default: - return DEMUXER_CTRL_NOTIMPL; + return DEMUXER_CTRL_NOTIMPL; } } const demuxer_desc_t demuxer_desc_matroska = { - "Matroska demuxer", - "mkv", - "Matroska", - "Aurelien Jacobs", - "", - DEMUXER_TYPE_MATROSKA, - 1, // safe autodetect - demux_mkv_open, - demux_mkv_fill_buffer, - NULL, - demux_close_mkv, - demux_mkv_seek, - demux_mkv_control + "Matroska demuxer", + "mkv", + "Matroska", + "Aurelien Jacobs", + "", + DEMUXER_TYPE_MATROSKA, + 1, // safe autodetect + demux_mkv_open, + demux_mkv_fill_buffer, + NULL, + demux_close_mkv, + demux_mkv_seek, + demux_mkv_control }; diff --git a/libmpdemux/ebml.c b/libmpdemux/ebml.c index d22314fa8d..33991e8781 100644 --- a/libmpdemux/ebml.c +++ b/libmpdemux/ebml.c @@ -39,161 +39,151 @@ * Read: the element content data ID. * Return: the ID. */ -uint32_t -ebml_read_id (stream_t *s, int *length) +uint32_t ebml_read_id(stream_t *s, int *length) { - int i, len_mask = 0x80; - uint32_t id; + int i, len_mask = 0x80; + uint32_t id; - for (i=0, id=stream_read_char (s); i<4 && !(id & len_mask); i++) - len_mask >>= 1; - if (i >= 4) - return EBML_ID_INVALID; - if (length) - *length = i + 1; - while (i--) - id = (id << 8) | stream_read_char (s); - return id; + for (i = 0, id = stream_read_char(s); i < 4 && !(id & len_mask); i++) + len_mask >>= 1; + if (i >= 4) + return EBML_ID_INVALID; + if (length) + *length = i + 1; + while (i--) + id = (id << 8) | stream_read_char(s); + return id; } /* * Read a variable length unsigned int. */ -uint64_t -ebml_read_vlen_uint (uint8_t *buffer, int *length) +uint64_t ebml_read_vlen_uint(uint8_t *buffer, int *length) { - int i, j, num_ffs = 0, len_mask = 0x80; - uint64_t num; + int i, j, num_ffs = 0, len_mask = 0x80; + uint64_t num; - for (i=0, num=*buffer++; i<8 && !(num & len_mask); i++) - len_mask >>= 1; - if (i >= 8) - return EBML_UINT_INVALID; - j = i+1; - if (length) - *length = j; - if ((int)(num &= (len_mask - 1)) == len_mask - 1) - num_ffs++; - while (i--) - { - num = (num << 8) | *buffer++; - if ((num & 0xFF) == 0xFF) + for (i = 0, num = *buffer++; i < 8 && !(num & len_mask); i++) + len_mask >>= 1; + if (i >= 8) + return EBML_UINT_INVALID; + j = i + 1; + if (length) + *length = j; + if ((int) (num &= (len_mask - 1)) == len_mask - 1) num_ffs++; + while (i--) { + num = (num << 8) | *buffer++; + if ((num & 0xFF) == 0xFF) + num_ffs++; } - if (j == num_ffs) - return EBML_UINT_INVALID; - return num; + if (j == num_ffs) + return EBML_UINT_INVALID; + return num; } /* * Read a variable length signed int. */ -int64_t -ebml_read_vlen_int (uint8_t *buffer, int *length) +int64_t ebml_read_vlen_int(uint8_t *buffer, int *length) { - uint64_t unum; - int l; + uint64_t unum; + int l; - /* read as unsigned number first */ - unum = ebml_read_vlen_uint (buffer, &l); - if (unum == EBML_UINT_INVALID) - return EBML_INT_INVALID; - if (length) - *length = l; + /* read as unsigned number first */ + unum = ebml_read_vlen_uint(buffer, &l); + if (unum == EBML_UINT_INVALID) + return EBML_INT_INVALID; + if (length) + *length = l; - return unum - ((1 << ((7 * l) - 1)) - 1); + return unum - ((1 << ((7 * l) - 1)) - 1); } /* * Read: element content length. */ -uint64_t -ebml_read_length (stream_t *s, int *length) +uint64_t ebml_read_length(stream_t *s, int *length) { - int i, j, num_ffs = 0, len_mask = 0x80; - uint64_t len; + int i, j, num_ffs = 0, len_mask = 0x80; + uint64_t len; - for (i=0, len=stream_read_char (s); i<8 && !(len & len_mask); i++) - len_mask >>= 1; - if (i >= 8) - return EBML_UINT_INVALID; - j = i+1; - if (length) - *length = j; - if ((int)(len &= (len_mask - 1)) == len_mask - 1) - num_ffs++; - while (i--) - { - len = (len << 8) | stream_read_char (s); - if ((len & 0xFF) == 0xFF) + for (i = 0, len = stream_read_char(s); i < 8 && !(len & len_mask); i++) + len_mask >>= 1; + if (i >= 8) + return EBML_UINT_INVALID; + j = i + 1; + if (length) + *length = j; + if ((int) (len &= (len_mask - 1)) == len_mask - 1) num_ffs++; + while (i--) { + len = (len << 8) | stream_read_char(s); + if ((len & 0xFF) == 0xFF) + num_ffs++; } - if (j == num_ffs) - return EBML_UINT_INVALID; - return len; + if (j == num_ffs) + return EBML_UINT_INVALID; + return len; } /* * Read the next element as an unsigned int. */ -uint64_t -ebml_read_uint (stream_t *s, uint64_t *length) +uint64_t ebml_read_uint(stream_t *s, uint64_t *length) { - uint64_t len, value = 0; - int l; + uint64_t len, value = 0; + int l; - len = ebml_read_length (s, &l); - if (len == EBML_UINT_INVALID || len < 1 || len > 8) - return EBML_UINT_INVALID; - if (length) - *length = len + l; + len = ebml_read_length(s, &l); + if (len == EBML_UINT_INVALID || len < 1 || len > 8) + return EBML_UINT_INVALID; + if (length) + *length = len + l; - while (len--) - value = (value << 8) | stream_read_char (s); + while (len--) + value = (value << 8) | stream_read_char(s); - return value; + return value; } /* * Read the next element as a signed int. */ -int64_t -ebml_read_int (stream_t *s, uint64_t *length) +int64_t ebml_read_int(stream_t *s, uint64_t *length) { - int64_t value = 0; - uint64_t len; - int l; + int64_t value = 0; + uint64_t len; + int l; - len = ebml_read_length (s, &l); - if (len == EBML_UINT_INVALID || len < 1 || len > 8) - return EBML_INT_INVALID; - if (length) - *length = len + l; + len = ebml_read_length(s, &l); + if (len == EBML_UINT_INVALID || len < 1 || len > 8) + return EBML_INT_INVALID; + if (length) + *length = len + l; - len--; - l = stream_read_char (s); - if (l & 0x80) - value = -1; - value = (value << 8) | l; - while (len--) - value = (value << 8) | stream_read_char (s); + len--; + l = stream_read_char(s); + if (l & 0x80) + value = -1; + value = (value << 8) | l; + while (len--) + value = (value << 8) | stream_read_char(s); - return value; + return value; } /* * Read the next element as a float. */ -long double -ebml_read_float (stream_t *s, uint64_t *length) +long double ebml_read_float(stream_t *s, uint64_t *length) { - long double value; - uint64_t len; - int l; + long double value; + uint64_t len; + int l; - len = ebml_read_length (s, &l); - switch (len) - { + len = ebml_read_length(s, &l); + switch (len) { case 4: value = av_int2flt(stream_read_dword(s)); break; @@ -203,168 +193,160 @@ ebml_read_float (stream_t *s, uint64_t *length) break; default: - return EBML_FLOAT_INVALID; + return EBML_FLOAT_INVALID; } - if (length) - *length = len + l; + if (length) + *length = len + l; - return value; + return value; } /* * Read the next element as an ASCII string. */ -char * -ebml_read_ascii (stream_t *s, uint64_t *length) +char *ebml_read_ascii(stream_t *s, uint64_t *length) { - uint64_t len; - char *str; - int l; + uint64_t len; + char *str; + int l; - len = ebml_read_length (s, &l); - if (len == EBML_UINT_INVALID) - return NULL; - if (len > SIZE_MAX - 1) - return NULL; - if (length) - *length = len + l; + len = ebml_read_length(s, &l); + if (len == EBML_UINT_INVALID) + return NULL; + if (len > SIZE_MAX - 1) + return NULL; + if (length) + *length = len + l; - str = malloc (len + 1); - if (stream_read(s, str, len) != (int) len) - { - free (str); - return NULL; + str = malloc(len + 1); + if (stream_read(s, str, len) != (int) len) { + free(str); + return NULL; } - str[len] = '\0'; + str[len] = '\0'; - return str; + return str; } /* * Read the next element as a UTF-8 string. */ -char * -ebml_read_utf8 (stream_t *s, uint64_t *length) +char *ebml_read_utf8(stream_t *s, uint64_t *length) { - return ebml_read_ascii (s, length); + return ebml_read_ascii(s, length); } /* * Skip the next element. */ -int -ebml_read_skip (stream_t *s, uint64_t *length) +int ebml_read_skip(stream_t *s, uint64_t *length) { - uint64_t len; - int l; + uint64_t len; + int l; - len = ebml_read_length (s, &l); - if (len == EBML_UINT_INVALID) - return 1; - if (length) - *length = len + l; + len = ebml_read_length(s, &l); + if (len == EBML_UINT_INVALID) + return 1; + if (length) + *length = len + l; - stream_skip(s, len); + stream_skip(s, len); - return 0; + return 0; } /* * Read the next element, but only the header. The contents * are supposed to be sub-elements which can be read separately. */ -uint32_t -ebml_read_master (stream_t *s, uint64_t *length) +uint32_t ebml_read_master(stream_t *s, uint64_t *length) { - uint64_t len; - uint32_t id; + uint64_t len; + uint32_t id; + + id = ebml_read_id(s, NULL); + if (id == EBML_ID_INVALID) + return id; + + len = ebml_read_length(s, NULL); + if (len == EBML_UINT_INVALID) + return EBML_ID_INVALID; + if (length) + *length = len; - id = ebml_read_id (s, NULL); - if (id == EBML_ID_INVALID) return id; - - len = ebml_read_length (s, NULL); - if (len == EBML_UINT_INVALID) - return EBML_ID_INVALID; - if (length) - *length = len; - - return id; } /* * Read an EBML header. */ -char * -ebml_read_header (stream_t *s, int *version) +char *ebml_read_header(stream_t *s, int *version) { - uint64_t length, l, num; - uint32_t id; - char *str = NULL; + uint64_t length, l, num; + uint32_t id; + char *str = NULL; - if (ebml_read_master (s, &length) != EBML_ID_HEADER) - return 0; + if (ebml_read_master(s, &length) != EBML_ID_HEADER) + return 0; - if (version) - *version = 1; + if (version) + *version = 1; - while (length > 0) - { - id = ebml_read_id (s, NULL); - if (id == EBML_ID_INVALID) - return NULL; - length -= 2; + while (length > 0) { + id = ebml_read_id(s, NULL); + if (id == EBML_ID_INVALID) + return NULL; + length -= 2; - switch (id) - { - /* is our read version uptodate? */ + switch (id) { + /* is our read version uptodate? */ case EBML_ID_EBMLREADVERSION: - num = ebml_read_uint (s, &l); - if (num != EBML_VERSION) - return NULL; - break; + num = ebml_read_uint(s, &l); + if (num != EBML_VERSION) + return NULL; + break; - /* we only handle 8 byte lengths at max */ + /* we only handle 8 byte lengths at max */ case EBML_ID_EBMLMAXSIZELENGTH: - num = ebml_read_uint (s, &l); - if (num != sizeof (uint64_t)) - return NULL; - break; + num = ebml_read_uint(s, &l); + if (num != sizeof(uint64_t)) + return NULL; + break; - /* we handle 4 byte IDs at max */ + /* we handle 4 byte IDs at max */ case EBML_ID_EBMLMAXIDLENGTH: - num = ebml_read_uint (s, &l); - if (num != sizeof (uint32_t)) - return NULL; - break; + num = ebml_read_uint(s, &l); + if (num != sizeof(uint32_t)) + return NULL; + break; case EBML_ID_DOCTYPE: - str = ebml_read_ascii (s, &l); - if (str == NULL) - return NULL; - break; + str = ebml_read_ascii(s, &l); + if (str == NULL) + return NULL; + break; case EBML_ID_DOCTYPEREADVERSION: - num = ebml_read_uint (s, &l); - if (num == EBML_UINT_INVALID) - return NULL; - if (version) - *version = num; - break; + num = ebml_read_uint(s, &l); + if (num == EBML_UINT_INVALID) + return NULL; + if (version) + *version = num; + break; - /* we ignore these two, they don't tell us anything we care about */ + /* we ignore these two, they don't tell us anything we care about */ case EBML_ID_VOID: case EBML_ID_EBMLVERSION: case EBML_ID_DOCTYPEVERSION: default: - if (ebml_read_skip (s, &l)) - return NULL; - break; + if (ebml_read_skip(s, &l)) + return NULL; + break; } - length -= l; + length -= l; } - return str; + return str; } From 069f0d026c16403fda300ee7db62027fc1be1739 Mon Sep 17 00:00:00 2001 From: diego Date: Thu, 27 May 2010 18:15:04 +0000 Subject: [PATCH 38/55] Drop pointless _s suffix from struct ao_data. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31235 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libao2/audio_out.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libao2/audio_out.h b/libao2/audio_out.h index 049cfc5f21..e483a88422 100644 --- a/libao2/audio_out.h +++ b/libao2/audio_out.h @@ -47,8 +47,7 @@ typedef struct ao_functions_s } ao_functions_t; /* global data used by mplayer and plugins */ -typedef struct ao_data_s -{ +typedef struct ao_data { int samplerate; int channels; int format; From 5e71e43bb59d497d6db7312bc41c2b244a83d621 Mon Sep 17 00:00:00 2001 From: diego Date: Thu, 27 May 2010 20:38:25 +0000 Subject: [PATCH 39/55] Drop pointless _st suffix from 'struct stream'. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31237 b3059339-0415-0410-9bf9-f77b7e298cf2 --- playtree.h | 4 ++-- playtreeparser.h | 6 +++--- stream/stream.h | 16 ++++++++-------- stream/stream_netstream.c | 6 +++--- stream/stream_radio.c | 18 +++++++++--------- stream/stream_radio.h | 12 ++++++------ stream/stream_rtsp.c | 2 +- stream/stream_vstream.c | 4 ++-- subreader.h | 6 +++--- 9 files changed, 37 insertions(+), 37 deletions(-) diff --git a/playtree.h b/playtree.h index 73bedde082..210f6de916 100644 --- a/playtree.h +++ b/playtree.h @@ -22,7 +22,7 @@ /// \file /// \ingroup Playtree -struct stream_st; +struct stream; struct m_config; /// \defgroup PlaytreeIterReturn Playtree iterator return code @@ -246,7 +246,7 @@ play_tree_iter_get_file(play_tree_iter_t* iter, int d); /** \ingroup PlaytreeParser */ play_tree_t* -parse_playtree(struct stream_st *stream, int forced); +parse_playtree(struct stream *stream, int forced); /// Clean a tree by destroying all empty elements. play_tree_t* diff --git a/playtreeparser.h b/playtreeparser.h index 53744ac0a2..1186d152a2 100644 --- a/playtreeparser.h +++ b/playtreeparser.h @@ -30,10 +30,10 @@ /// \file -struct stream_st; +struct stream; typedef struct play_tree_parser { - struct stream_st* stream; + struct stream *stream; char *buffer,*iter,*line; int buffer_size , buffer_end; int deep,keep; @@ -46,7 +46,7 @@ typedef struct play_tree_parser { * \return The new parser. */ play_tree_parser_t* -play_tree_parser_new(struct stream_st* stream,int deep); +play_tree_parser_new(struct stream *stream, int deep); /// Destroy a parser. void diff --git a/stream/stream.h b/stream/stream.h index 2810839959..b21e1a7a90 100644 --- a/stream/stream.h +++ b/stream/stream.h @@ -114,7 +114,7 @@ typedef struct streaming_control { void *data; } streaming_ctrl_t; -struct stream_st; +struct stream; typedef struct stream_info_st { const char *info; const char *name; @@ -123,7 +123,7 @@ typedef struct stream_info_st { /// mode isn't used atm (ie always READ) but it shouldn't be ignored /// opts is at least in it's defaults settings and may have been /// altered by url parsing if enabled and the options string parsing. - int (*open)(struct stream_st* st, int mode, void* opts, int* file_format); + int (*open)(struct stream* st, int mode, void* opts, int* file_format); const char* protocols[MAX_STREAM_PROTOCOLS]; const void* opts; int opts_url; /* If this is 1 we will parse the url as an option string @@ -131,19 +131,19 @@ typedef struct stream_info_st { * options string given to open_stream_plugin */ } stream_info_t; -typedef struct stream_st { +typedef struct stream { // Read - int (*fill_buffer)(struct stream_st *s, char* buffer, int max_len); + int (*fill_buffer)(struct stream *s, char* buffer, int max_len); // Write - int (*write_buffer)(struct stream_st *s, char* buffer, int len); + int (*write_buffer)(struct stream *s, char* buffer, int len); // Seek - int (*seek)(struct stream_st *s,off_t pos); + int (*seek)(struct stream *s,off_t pos); // Control // Will be later used to let streams like dvd and cdda report // their structure (ie tracks, chapters, etc) - int (*control)(struct stream_st *s,int cmd,void* arg); + int (*control)(struct stream *s,int cmd,void* arg); // Close - void (*close)(struct stream_st *s); + void (*close)(struct stream *s); int fd; // file descriptor, see man open(2) int type; // see STREAMTYPE_* diff --git a/stream/stream_netstream.c b/stream/stream_netstream.c index c0a80689df..47d1baad89 100644 --- a/stream/stream_netstream.c +++ b/stream/stream_netstream.c @@ -201,7 +201,7 @@ static int seek(stream_t *s,off_t newpos) { return 1; } -static int net_stream_reset(struct stream_st *s) { +static int net_stream_reset(struct stream *s) { mp_net_stream_packet_t* pack; pack = send_net_stream_cmd(s,NET_STREAM_RESET,NULL,0); @@ -212,7 +212,7 @@ static int net_stream_reset(struct stream_st *s) { return 1; } -static int control(struct stream_st *s,int cmd,void* arg) { +static int control(struct stream *s,int cmd,void* arg) { switch(cmd) { case STREAM_CTRL_RESET: return net_stream_reset(s); @@ -220,7 +220,7 @@ static int control(struct stream_st *s,int cmd,void* arg) { return STREAM_UNSUPPORTED; } -static void close_s(struct stream_st *s) { +static void close_s(struct stream *s) { mp_net_stream_packet_t* pack; pack = send_net_stream_cmd(s,NET_STREAM_CLOSE,NULL,0); diff --git a/stream/stream_radio.c b/stream/stream_radio.c index 76088d180e..15d43ada57 100644 --- a/stream/stream_radio.c +++ b/stream/stream_radio.c @@ -155,7 +155,7 @@ static const struct m_struct_st stream_opts = { stream_opts_fields }; -static void close_s(struct stream_st * stream); +static void close_s(struct stream *stream); #ifdef CONFIG_RADIO_CAPTURE static int clear_buffer(radio_priv_t* priv); #endif @@ -900,7 +900,7 @@ static int init_audio(radio_priv_t *priv) * \parameter frequency pointer to float, which will contain frequency in MHz * \return 1 if success,0 - otherwise */ -int radio_get_freq(struct stream_st *stream, float* frequency){ +int radio_get_freq(struct stream *stream, float *frequency){ radio_priv_t* priv=(radio_priv_t*)stream->priv; if (!frequency) @@ -915,7 +915,7 @@ int radio_get_freq(struct stream_st *stream, float* frequency){ * \parameter frequency frequency in MHz * \return 1 if success,0 - otherwise */ -int radio_set_freq(struct stream_st *stream, float frequency){ +int radio_set_freq(struct stream *stream, float frequency){ radio_priv_t* priv=(radio_priv_t*)stream->priv; if (set_frequency(priv,frequency)!=STREAM_OK){ @@ -934,7 +934,7 @@ int radio_set_freq(struct stream_st *stream, float frequency){ * \return 1 if success,0 - otherwise * */ -int radio_step_freq(struct stream_st *stream, float step_interval){ +int radio_step_freq(struct stream *stream, float step_interval){ float frequency; radio_priv_t* priv=(radio_priv_t*)stream->priv; @@ -957,7 +957,7 @@ int radio_step_freq(struct stream_st *stream, float step_interval){ * if channel parameter is NULL function prints error message and does nothing, otherwise * changes channel to prev or next in list */ -int radio_step_channel(struct stream_st *stream, int direction) { +int radio_step_channel(struct stream *stream, int direction) { radio_priv_t* priv=(radio_priv_t*)stream->priv; if (priv->radio_channel_list) { @@ -999,7 +999,7 @@ int radio_step_channel(struct stream_st *stream, int direction) { * if channel parameter is NULL function prints error message and does nothing, otherwise * changes channel to given */ -int radio_set_channel(struct stream_st *stream, char *channel) { +int radio_set_channel(struct stream *stream, char *channel) { radio_priv_t* priv=(radio_priv_t*)stream->priv; int i, channel_int; radio_channels_t* tmp; @@ -1047,7 +1047,7 @@ int radio_set_channel(struct stream_st *stream, char *channel) { * * NOTE: return value may be NULL (e.g. when channel list not initialized) */ -char* radio_get_channel_name(struct stream_st *stream){ +char* radio_get_channel_name(struct stream *stream){ radio_priv_t* priv=(radio_priv_t*)stream->priv; if (priv->radio_channel_current) { return priv->radio_channel_current->name; @@ -1059,7 +1059,7 @@ char* radio_get_channel_name(struct stream_st *stream){ * \brief fills given buffer with audio data * \return number of bytes, written into buffer */ -static int fill_buffer_s(struct stream_st *s, char* buffer, int max_len){ +static int fill_buffer_s(struct stream *s, char* buffer, int max_len){ int len=max_len; #ifdef CONFIG_RADIO_CAPTURE @@ -1220,7 +1220,7 @@ static int open_s(stream_t *stream,int mode, void* opts, int* file_format) { /***************************************************************** * Close stream. Clear structures. */ -static void close_s(struct stream_st * stream){ +static void close_s(struct stream *stream){ radio_priv_t* priv=(radio_priv_t*)stream->priv; radio_channels_t * tmp; if (!priv) return; diff --git a/stream/stream_radio.h b/stream/stream_radio.h index 1af2f1f4b0..8e3df1edb9 100644 --- a/stream/stream_radio.h +++ b/stream/stream_radio.h @@ -55,11 +55,11 @@ typedef struct radio_param_s{ extern radio_param_t stream_radio_defaults; -int radio_set_freq(struct stream_st *stream, float freq); -int radio_get_freq(struct stream_st *stream, float* freq); -char* radio_get_channel_name(struct stream_st *stream); -int radio_set_channel(struct stream_st *stream, char *channel); -int radio_step_channel(struct stream_st *stream, int direction); -int radio_step_freq(struct stream_st *stream, float step_interval); +int radio_set_freq(struct stream *stream, float freq); +int radio_get_freq(struct stream *stream, float* freq); +char* radio_get_channel_name(struct stream *stream); +int radio_set_channel(struct stream *stream, char *channel); +int radio_step_channel(struct stream *stream, int direction); +int radio_step_freq(struct stream *stream, float step_interval); #endif /* MPLAYER_STREAM_RADIO_H */ diff --git a/stream/stream_rtsp.c b/stream/stream_rtsp.c index 336db6144c..e02255e531 100644 --- a/stream/stream_rtsp.c +++ b/stream/stream_rtsp.c @@ -130,7 +130,7 @@ rtsp_streaming_start (stream_t *stream) } static void -rtsp_streaming_close (struct stream_st *s) +rtsp_streaming_close (struct stream *s) { rtsp_session_t *rtsp = NULL; diff --git a/stream/stream_vstream.c b/stream/stream_vstream.c index ff173855f5..3cb0bd9bc6 100644 --- a/stream/stream_vstream.c +++ b/stream/stream_vstream.c @@ -95,11 +95,11 @@ static int seek(stream_t *s,off_t newpos) { return 1; } -static int control(struct stream_st *s,int cmd,void* arg) { +static int control(struct stream *s, int cmd, void *arg) { return STREAM_UNSUPPORTED; } -static void close_s(struct stream_st *s) { +static void close_s(struct stream *s) { } static int open_s(stream_t *stream, int mode, void* opts, int* file_format) { diff --git a/subreader.h b/subreader.h index 3893124f5a..bc646f9dcb 100644 --- a/subreader.h +++ b/subreader.h @@ -88,12 +88,12 @@ sub_data* sub_read_file (char *filename, float pts); subtitle* subcp_recode (subtitle *sub); // enca_fd is the file enca uses to determine the codepage. // setting to NULL disables enca. -struct stream_st; -void subcp_open (struct stream_st *st); /* for demux_ogg.c */ +struct stream; +void subcp_open (struct stream *st); /* for demux_ogg.c */ void subcp_close (void); /* for demux_ogg.c */ #ifdef CONFIG_ENCA const char* guess_buffer_cp(unsigned char* buffer, int buflen, const char *preferred_language, const char *fallback); -const char* guess_cp(struct stream_st *st, const char *preferred_language, const char *fallback); +const char* guess_cp(struct stream *st, const char *preferred_language, const char *fallback); #endif char ** sub_filenames(const char *path, char *fname); void list_sub_file(sub_data* subd); From 5796e96b36e74fe4dc9a04a379667ea056aa4a4e Mon Sep 17 00:00:00 2001 From: diego Date: Thu, 27 May 2010 20:59:40 +0000 Subject: [PATCH 40/55] Drop pointless _s suffix from 'struct af_stream'. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31238 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libaf/af.h | 2 +- libmpdemux/stheader.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libaf/af.h b/libaf/af.h index b6b546525e..fe146906e9 100644 --- a/libaf/af.h +++ b/libaf/af.h @@ -106,7 +106,7 @@ typedef struct af_cfg_s{ }af_cfg_t; // Current audio stream -typedef struct af_stream_s +typedef struct af_stream { // The first and last filter in the list af_instance_t* first; diff --git a/libmpdemux/stheader.h b/libmpdemux/stheader.h index d7adc6478b..b39ef8cfac 100644 --- a/libmpdemux/stheader.h +++ b/libmpdemux/stheader.h @@ -72,7 +72,7 @@ typedef struct sh_audio { int a_out_buffer_len; int a_out_buffer_size; // void* audio_out; // the audio_out handle, used for this audio stream - struct af_stream_s *afilter; // the audio filter stream + struct af_stream *afilter; // the audio filter stream struct ad_functions *ad_driver; #ifdef CONFIG_DYNAMIC_PLUGINS void *dec_handle; From ae85fe1d2f278bfa4d9c8bdebfc4e90c033787c7 Mon Sep 17 00:00:00 2001 From: diego Date: Thu, 27 May 2010 22:18:10 +0000 Subject: [PATCH 41/55] Fix a bunch of typos in the stream cache code. patch by Giorgio Vazzana, mywing81 gmail com git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31242 b3059339-0415-0410-9bf9-f77b7e298cf2 --- stream/cache2.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/stream/cache2.c b/stream/cache2.c index 533781104b..e534f381c7 100644 --- a/stream/cache2.c +++ b/stream/cache2.c @@ -19,11 +19,11 @@ #include "config.h" // Initial draft of my new cache system... -// Note it runs in 2 processes (using fork()), but doesn't requires locking!! +// Note it runs in 2 processes (using fork()), but doesn't require locking!! // TODO: seeking, data consistency checking #define READ_USLEEP_TIME 10000 -// These defines are used to reduce the cost of many succesive +// These defines are used to reduce the cost of many successive // seeks (e.g. when a file has no index) by spinning quickly at first. #define INITIAL_FILL_USLEEP_TIME 1000 #define INITIAL_FILL_USLEEP_COUNT 10 @@ -68,12 +68,12 @@ extern int use_gui; typedef struct { // constats: - unsigned char *buffer; // base pointer of the alllocated buffer memory - int buffer_size; // size of the alllocated buffer memory + unsigned char *buffer; // base pointer of the allocated buffer memory + int buffer_size; // size of the allocated buffer memory int sector_size; // size of a single sector (2048/2324) int back_size; // we should keep back_size amount of old bytes for backward seek int fill_limit; // we should fill buffer only if space>=fill_limit - int seek_limit; // keep filling cache if distanse is less that seek limit + int seek_limit; // keep filling cache if distance is less that seek limit // filler's pointers: int eof; off_t min_filepos; // buffer contain only a part of the file, from min-max pos @@ -394,7 +394,7 @@ int stream_enable_cache(stream_t *stream,int size,int min,int seek_limit){ //make sure that we won't wait from cache_fill - //more data than it is alowed to fill + //more data than it is allowed to fill if (s->seek_limit > s->buffer_size - s->fill_limit ){ s->seek_limit = s->buffer_size - s->fill_limit; } From 76c2abc99f43d87e43e404b90a6fd49c0e076333 Mon Sep 17 00:00:00 2001 From: diego Date: Thu, 27 May 2010 22:43:14 +0000 Subject: [PATCH 42/55] small cosmetics for the 1.0rc3 changelog git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31243 b3059339-0415-0410-9bf9-f77b7e298cf2 --- Changelog | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Changelog b/Changelog index 9a24914a59..897312f5d3 100644 --- a/Changelog +++ b/Changelog @@ -60,6 +60,8 @@ MPlayer (1.0) MEncoder: * add -tsprog for demuxer lavf + + rc3: "BikeshedCounter" March 27, 2009 Decoders: * support for X8 frames (fixes "J-type picture is not supported" for WMV2) @@ -80,7 +82,7 @@ MPlayer (1.0) * GeoVision Advanced MPEG-4 (GMP4, GM40) via binary DLL * Xiricam JPEG from Veo PC Camera (XJPG) via binary DLL * WorldConnect Wavelet Video (SMSV) via binary DLL - * VDOWave 3 advanced (VDO3,VDOM,VDOW) via binary DLL + * VDOWave 3 advanced (VDO3, VDOM, VDOW) via binary DLL * VoxWare MetaVoice (format 0x0074) via binary DLL * Ulead DV Audio (0x215,0x216) via binary DLL * GoToMeeting codec (G2M2,G2M3) via binary DLL @@ -89,10 +91,10 @@ MPlayer (1.0) * ZDSoft screen recorder (ZDSV) via binary DLL * WebTrain Communication lossless screen recorder (WTVC) via binary DLL * xfire video (XFR1) via binary DLL - * VFAPI rgb transcode (vifp) via binary DLL + * VFAPI RGB transcode (vifp) via binary DLL * ETI CamCorder EYECON (NUB0,NUB1,NUB2) via binary DLL * fox motion (FMVC) via binary DLL - * Trident video (TY2C,TY2N,TY0N) via binary DLL + * Trident video (TY2C, TY2N, TY0N) via binary DLL * 10-bit video (v210) via Cinewave binary DLL * Brooktree YUV 4:1:1 Raw (Y41P) via binary DLL * many rare/obscure fourccs for known formats added @@ -123,7 +125,7 @@ MPlayer (1.0) * change vf_screenshot dependency from libpng to lavc * add af_scaletempo which maintains audio pitch when changing playback speed * fix multi-channel reordering - * af_stats, filter to print information about the audio stream + * af_stats filter to print information about the audio stream * remove vf_yuy2, functionality is replaced by -vf format=yuv2 Streaming: @@ -242,10 +244,10 @@ MPlayer (1.0) Ports: * small crash with vo_macosx fixed * AC3/DTS passthrough for ao_macosx - * fix frozen OSD on Mac OS X + * fix frozen OSD on OS X * vo_gl now works with -wid and nVidia drivers on Windows (this is a hack) * VIDIX on SuperH - * workarounds for AltiVec on Apple gcc 3.3 on Mac OS X dropped + * workarounds for AltiVec on Apple gcc 3.3 on OS X dropped * vo_macosx can now be compiled in 64-bits mode * allow multiple MPlayer instances with vo_macosx using buffer_name * OpenGL support for unmodified MinGW64 From 3e830f876e497c1eb17b86877b9322c0cfae401a Mon Sep 17 00:00:00 2001 From: diego Date: Thu, 27 May 2010 22:43:49 +0000 Subject: [PATCH 43/55] vf_yuy2 was removed after the 1.0rc3 branch was cut. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31244 b3059339-0415-0410-9bf9-f77b7e298cf2 --- Changelog | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index 897312f5d3..7a38b760f4 100644 --- a/Changelog +++ b/Changelog @@ -25,6 +25,9 @@ MPlayer (1.0) * fix length in ASF/WMV files * support ISDB-Tb DVB streams + Filters: + * remove vf_yuy2, functionality is replaced by -vf format=yuv2 + Drivers: * -vo md5sum md5 calculation changed so output matches FFmpeg's -f framemd5 * Support for more formats in OpenGL video output drivers (different YUV @@ -126,7 +129,6 @@ MPlayer (1.0) * add af_scaletempo which maintains audio pitch when changing playback speed * fix multi-channel reordering * af_stats filter to print information about the audio stream - * remove vf_yuy2, functionality is replaced by -vf format=yuv2 Streaming: * tv:// support for Windows From 495115f2f11e90b5ad5e94f1326d29244b7b174a Mon Sep 17 00:00:00 2001 From: diego Date: Thu, 27 May 2010 23:21:16 +0000 Subject: [PATCH 44/55] cosmetics: vertical alignment in msg module help output. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31245 b3059339-0415-0410-9bf9-f77b7e298cf2 --- cfg-common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cfg-common.h b/cfg-common.h index f910adc5fe..b4e8d718a4 100644 --- a/cfg-common.h +++ b/cfg-common.h @@ -353,7 +353,7 @@ const m_option_t msgl_config[]={ " netst - Netstream\n" " muxer - muxer layer\n" " identify - identify output\n" - " ass - libass messages\n" + " ass - libass messages\n" " statusline - playback/encoding status line\n" "\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL}, {NULL, NULL, 0, 0, 0, 0, NULL} From 72ba1c8fec36da67fdbede8e8443d810823fdf76 Mon Sep 17 00:00:00 2001 From: diego Date: Thu, 27 May 2010 23:36:03 +0000 Subject: [PATCH 45/55] Drop pointles _st suffix from struct mp_cmd_filter and mp_cmd_bind_section. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31246 b3059339-0415-0410-9bf9-f77b7e298cf2 --- input/input.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/input/input.c b/input/input.c index 0bcd5752af..16a0a20f50 100644 --- a/input/input.c +++ b/input/input.c @@ -541,17 +541,17 @@ typedef struct mp_input_fd { int pos,size; } mp_input_fd_t; -typedef struct mp_cmd_filter_st mp_cmd_filter_t; +typedef struct mp_cmd_filter mp_cmd_filter_t; -struct mp_cmd_filter_st { +struct mp_cmd_filter { mp_input_cmd_filter filter; void* ctx; mp_cmd_filter_t* next; }; -typedef struct mp_cmd_bind_section_st mp_cmd_bind_section_t; +typedef struct mp_cmd_bind_section mp_cmd_bind_section_t; -struct mp_cmd_bind_section_st { +struct mp_cmd_bind_section { mp_cmd_bind_t* cmd_binds; char* section; mp_cmd_bind_section_t* next; From c0262f74351d78545d4e608201b9bb6170891e7d Mon Sep 17 00:00:00 2001 From: diego Date: Fri, 28 May 2010 00:25:28 +0000 Subject: [PATCH 46/55] Drop pointless _t suffix from 'struct lavf_priv'. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31247 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libmpdemux/demux_lavf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libmpdemux/demux_lavf.c b/libmpdemux/demux_lavf.c index dea34b72c2..bc1781c8a0 100644 --- a/libmpdemux/demux_lavf.c +++ b/libmpdemux/demux_lavf.c @@ -67,7 +67,7 @@ const m_option_t lavfdopts_conf[] = { #define BIO_BUFFER_SIZE 32768 -typedef struct lavf_priv_t{ +typedef struct lavf_priv { AVInputFormat *avif; AVFormatContext *avfc; ByteIOContext *pb; From f5f6bbaa090d51a3db670abb135d16e91250b1a3 Mon Sep 17 00:00:00 2001 From: diego Date: Fri, 28 May 2010 08:39:02 +0000 Subject: [PATCH 47/55] Remove commented-out declaration of nonexisting function uGetTimer(). git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31248 b3059339-0415-0410-9bf9-f77b7e298cf2 --- osdep/timer.h | 1 - 1 file changed, 1 deletion(-) diff --git a/osdep/timer.h b/osdep/timer.h index 2e4f2fc8fe..1d8c70e5fd 100644 --- a/osdep/timer.h +++ b/osdep/timer.h @@ -24,7 +24,6 @@ extern const char *timer_name; void InitTimer(void); unsigned int GetTimer(void); unsigned int GetTimerMS(void); -//int uGetTimer(void); float GetRelativeTime(void); int usec_sleep(int usec_delay); From 95e86309811d6dadf66c3d60e4f18e5165e78ba2 Mon Sep 17 00:00:00 2001 From: cehoyos Date: Fri, 28 May 2010 11:52:12 +0000 Subject: [PATCH 48/55] Use MSGT_DECVIDEO in a video decoder. Patch by Giorgio Vazzana, mywing81 gmail git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31249 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libmpcodecs/vd_theora.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libmpcodecs/vd_theora.c b/libmpcodecs/vd_theora.c index 9da6e2d6cd..f0efa250b7 100644 --- a/libmpcodecs/vd_theora.c +++ b/libmpcodecs/vd_theora.c @@ -99,7 +99,7 @@ static int init(sh_video_t *sh){ op.packet = extradata + 2; op.b_o_s = 1; if (extradata_size < op.bytes + 2) { - mp_msg(MSGT_DECAUDIO, MSGL_ERR, "Theora header too small\n"); + mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Theora header too small\n"); goto err_out; } extradata += op.bytes + 2; @@ -111,7 +111,7 @@ static int init(sh_video_t *sh){ if ( (errorCode = theora_decode_header (&context->inf, &context->cc, &op)) ) { - mp_msg(MSGT_DECAUDIO, MSGL_ERR, "Broken Theora header; errorCode=%i!\n", errorCode); + mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Broken Theora header; errorCode=%i!\n", errorCode); goto err_out; } } @@ -188,7 +188,7 @@ static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags) errorCode = theora_decode_YUVout (&context->st, &yuv); if (errorCode) { - mp_msg(MSGT_DEMUX,MSGL_ERR,"Theora decode YUVout failed: %i \n", + mp_msg(MSGT_DECVIDEO,MSGL_ERR,"Theora decode YUVout failed: %i \n", errorCode); return NULL; } From 4448190ef0c0c8029a3b3a41aab5b913ca0caa2b Mon Sep 17 00:00:00 2001 From: reimar Date: Fri, 28 May 2010 16:57:16 +0000 Subject: [PATCH 49/55] Fix cache process accidentally being killed by SIGUSR1. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31250 b3059339-0415-0410-9bf9-f77b7e298cf2 --- stream/cache2.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/stream/cache2.c b/stream/cache2.c index e534f381c7..e13f3e75f3 100644 --- a/stream/cache2.c +++ b/stream/cache2.c @@ -351,6 +351,9 @@ static void dummy_sighandler(int x) { */ static void cache_mainloop(cache_vars_t *s) { int sleep_count = 0; +#if FORKED_CACHE + signal(SIGUSR1, SIG_IGN); +#endif do { if (!cache_fill(s)) { #if FORKED_CACHE @@ -401,6 +404,10 @@ int stream_enable_cache(stream_t *stream,int size,int min,int seek_limit){ if (min > s->buffer_size - s->fill_limit) { min = s->buffer_size - s->fill_limit; } + // to make sure we wait for the cache process/thread to be active + // before continuing + if (min <= 0) + min = 1; #if FORKED_CACHE if((stream->cache_pid=fork())){ From 6f7c1ea40922a7093e07958dc12d5519505c5a63 Mon Sep 17 00:00:00 2001 From: reimar Date: Fri, 28 May 2010 17:26:31 +0000 Subject: [PATCH 50/55] Improve handling of cache process/thread hanging/being killed. In particular allow a single STRG+C to quit MPlayer. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31251 b3059339-0415-0410-9bf9-f77b7e298cf2 --- stream/cache2.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/stream/cache2.c b/stream/cache2.c index e13f3e75f3..dd9f4414a7 100644 --- a/stream/cache2.c +++ b/stream/cache2.c @@ -116,6 +116,8 @@ static void cache_stats(cache_vars_t *s) static int cache_read(cache_vars_t *s, unsigned char *buf, int size) { int total=0; + int sleep_count = 0; + int last_max = s->max_filepos; while(size>0){ int pos,newb,len; @@ -124,10 +126,21 @@ static int cache_read(cache_vars_t *s, unsigned char *buf, int size) if(s->read_filepos>=s->max_filepos || s->read_fileposmin_filepos){ // eof? if(s->eof) break; + if (s->max_filepos == last_max) { + if (sleep_count++ == 5) + mp_msg(MSGT_CACHE, MSGL_WARN, "Cache not filling!\n"); + } else { + last_max = s->max_filepos; + sleep_count = 0; + } // waiting for buffer fill... - usec_sleep(READ_USLEEP_TIME); // 10ms + if (stream_check_interrupt(READ_USLEEP_TIME)) { + s->eof = 1; + break; + } continue; // try again... } + sleep_count = 0; newb=s->max_filepos-s->read_filepos; // new bytes in the buffer if(newbcache_data; switch (cmd) { case STREAM_CTRL_SEEK_TO_TIME: @@ -562,8 +576,14 @@ int cache_do_control(stream_t *stream, int cmd, void *arg) { return STREAM_UNSUPPORTED; } cache_wakeup(stream); - while (s->control != -1) - usec_sleep(CONTROL_SLEEP_TIME); + while (s->control != -1) { + if (sleep_count++ == 1000) + mp_msg(MSGT_CACHE, MSGL_WARN, "Cache no responding!\n"); + if (stream_check_interrupt(CONTROL_SLEEP_TIME)) { + s->eof = 1; + return STREAM_UNSUPPORTED; + } + } switch (cmd) { case STREAM_CTRL_GET_TIME_LENGTH: case STREAM_CTRL_GET_CURRENT_TIME: From d7f19144b13fe6777c4cda6bbbe2598924d098c4 Mon Sep 17 00:00:00 2001 From: reimar Date: Fri, 28 May 2010 18:44:41 +0000 Subject: [PATCH 51/55] Document that time argument is in milliseconds. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31252 b3059339-0415-0410-9bf9-f77b7e298cf2 --- input/input.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/input/input.c b/input/input.c index 16a0a20f50..e3b7d68091 100644 --- a/input/input.c +++ b/input/input.c @@ -1203,6 +1203,9 @@ static mp_cmd_t *check_autorepeat(int paused) } +/** + * \param time time to wait at most for an event in milliseconds + */ static mp_cmd_t *read_events(int time, int paused) { int i; @@ -1899,6 +1902,9 @@ static int mp_input_print_cmd_list(m_option_t* cfg) { exit(0); } +/** + * \param time time to wait for an interruption in milliseconds + */ int mp_input_check_interrupt(int time) { mp_cmd_t* cmd; From 16e3978e1e1b2f8a302b7e45d4b09e602e6b8733 Mon Sep 17 00:00:00 2001 From: reimar Date: Fri, 28 May 2010 18:45:25 +0000 Subject: [PATCH 52/55] Document time scale for stream_check_interrupt argument. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31253 b3059339-0415-0410-9bf9-f77b7e298cf2 --- stream/stream.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stream/stream.h b/stream/stream.h index b21e1a7a90..1ff94a331c 100644 --- a/stream/stream.h +++ b/stream/stream.h @@ -327,7 +327,8 @@ stream_t* open_output_stream(const char* filename,char** options); /// Set the callback to be used by libstream to check for user /// interruption during long blocking operations (cache filling, etc). void stream_set_interrupt_callback(int (*cb)(int)); -/// Call the interrupt checking callback if there is one. +/// Call the interrupt checking callback if there is one and +/// wait for time milliseconds int stream_check_interrupt(int time); extern int dvd_title; From 27d41fa5b353be63e8578b49b33359ed11a82276 Mon Sep 17 00:00:00 2001 From: reimar Date: Fri, 28 May 2010 18:47:03 +0000 Subject: [PATCH 53/55] 100l, stream_check_for_interrupt argument is not in usec, so we would end up sleeping for 10s instead of 10ms. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31254 b3059339-0415-0410-9bf9-f77b7e298cf2 --- stream/cache2.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stream/cache2.c b/stream/cache2.c index dd9f4414a7..1e0bea9c7b 100644 --- a/stream/cache2.c +++ b/stream/cache2.c @@ -22,7 +22,7 @@ // Note it runs in 2 processes (using fork()), but doesn't require locking!! // TODO: seeking, data consistency checking -#define READ_USLEEP_TIME 10000 +#define READ_SLEEP_TIME 10 // These defines are used to reduce the cost of many successive // seeks (e.g. when a file has no index) by spinning quickly at first. #define INITIAL_FILL_USLEEP_TIME 1000 @@ -127,14 +127,14 @@ static int cache_read(cache_vars_t *s, unsigned char *buf, int size) // eof? if(s->eof) break; if (s->max_filepos == last_max) { - if (sleep_count++ == 5) + if (sleep_count++ == 10) mp_msg(MSGT_CACHE, MSGL_WARN, "Cache not filling!\n"); } else { last_max = s->max_filepos; sleep_count = 0; } // waiting for buffer fill... - if (stream_check_interrupt(READ_USLEEP_TIME)) { + if (stream_check_interrupt(READ_SLEEP_TIME)) { s->eof = 1; break; } From 6b255e5083d11a1026c94ad07b45f1fc3288b3e0 Mon Sep 17 00:00:00 2001 From: reimar Date: Fri, 28 May 2010 18:49:02 +0000 Subject: [PATCH 54/55] stream_check_interrupt should sleep even if no callback is set. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31255 b3059339-0415-0410-9bf9-f77b7e298cf2 --- stream/stream.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/stream/stream.c b/stream/stream.c index cdd9713a20..64c97cf0dc 100644 --- a/stream/stream.c +++ b/stream/stream.c @@ -486,7 +486,10 @@ void stream_set_interrupt_callback(int (*cb)(int)) { } int stream_check_interrupt(int time) { - if(!stream_check_interrupt_cb) return 0; + if(!stream_check_interrupt_cb) { + usec_sleep(time * 1000); + return 0; + } return stream_check_interrupt_cb(time); } From a564c5a6cc3eeeaa5b271aead5d05b90e6fdb041 Mon Sep 17 00:00:00 2001 From: reimar Date: Fri, 28 May 2010 20:59:53 +0000 Subject: [PATCH 55/55] Fix typo in message. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31256 b3059339-0415-0410-9bf9-f77b7e298cf2 --- stream/cache2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stream/cache2.c b/stream/cache2.c index 1e0bea9c7b..3748e6f2f4 100644 --- a/stream/cache2.c +++ b/stream/cache2.c @@ -578,7 +578,7 @@ int cache_do_control(stream_t *stream, int cmd, void *arg) { cache_wakeup(stream); while (s->control != -1) { if (sleep_count++ == 1000) - mp_msg(MSGT_CACHE, MSGL_WARN, "Cache no responding!\n"); + mp_msg(MSGT_CACHE, MSGL_WARN, "Cache not responding!\n"); if (stream_check_interrupt(CONTROL_SLEEP_TIME)) { s->eof = 1; return STREAM_UNSUPPORTED;