From c4f33d784a058325b26ba82f34c43dab0cb19dc8 Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 8 Jul 2013 00:35:04 +0200 Subject: demux: remove some old stream header functions --- stream/tv.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'stream/tv.c') diff --git a/stream/tv.c b/stream/tv.c index 1fcb13037d..83a0052563 100644 --- a/stream/tv.c +++ b/stream/tv.c @@ -708,7 +708,8 @@ static demuxer_t* demux_open_tv(demuxer_t *demuxer) funcs = tvh->functions; demuxer->priv=tvh; - sh_video = new_sh_video(demuxer, 0); + struct sh_stream *sh_v = new_sh_stream(demuxer, STREAM_VIDEO); + sh_video = sh_v->video; /* get IMAGE FORMAT */ int fourcc; @@ -786,7 +787,8 @@ static demuxer_t* demux_open_tv(demuxer_t *demuxer) goto no_audio; } - sh_audio = new_sh_audio(demuxer, 0); + struct sh_stream *sh_a = new_sh_stream(demuxer, STREAM_AUDIO); + sh_audio = sh_a->audio; funcs->control(tvh->priv, TVI_CONTROL_AUD_GET_SAMPLERATE, &sh_audio->samplerate); -- cgit v1.2.3 From 05ae5afd6249af9770eb1e55104fbd4f510c2342 Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 8 Jul 2013 01:26:13 +0200 Subject: demux: remove separate arrays for audio/video/sub streams, simplify These separate arrays were used by the old demuxers and are not needed anymore. We can simplify track switching as well. One interesting thing is that stream/tv.c (which is a demuxer) won't respect --no-audio anymore. It will probably work as expected, but it will still open an audio device etc. - this is because track selection is now always done with the runtime track switching mechanism. Maybe the TV code could be updated to do proper runtime switching, but I can't test this stuff. --- stream/tv.c | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'stream/tv.c') diff --git a/stream/tv.c b/stream/tv.c index 83a0052563..e5768a350a 100644 --- a/stream/tv.c +++ b/stream/tv.c @@ -739,20 +739,12 @@ static demuxer_t* demux_open_tv(demuxer_t *demuxer) tvh->tv_param->noaudio = 1; } - /* disable TV audio if -nosound is present */ - if (!demuxer->audio || demuxer->audio->id == -2) { - tvh->tv_param->noaudio = 1; - } - /* set width */ funcs->control(tvh->priv, TVI_CONTROL_VID_GET_WIDTH, &sh_video->disp_w); /* set height */ funcs->control(tvh->priv, TVI_CONTROL_VID_GET_HEIGHT, &sh_video->disp_h); - demuxer->video->sh = sh_video; - sh_video->ds = demuxer->video; - demuxer->video->id = 0; demuxer->seekable = 0; /* here comes audio init */ @@ -818,10 +810,6 @@ static demuxer_t* demux_open_tv(demuxer_t *demuxer) mp_tmsg(MSGT_DECVIDEO, MSGL_V, " TV audio: %d channels, %d bits, %d Hz\n", sh_audio->wf->nChannels, sh_audio->wf->wBitsPerSample, sh_audio->wf->nSamplesPerSec); - - demuxer->audio->sh = sh_audio; - sh_audio->ds = demuxer->audio; - demuxer->audio->id = 0; } no_audio: -- cgit v1.2.3 From 23e303859aa93572f00b17e3b2bc0a552ad7c348 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 11 Jul 2013 19:15:09 +0200 Subject: mplayer: fix incorrect audio sync after format changes This is not directly related to the handling of format changes itself, but playing audio normally after the change. This was broken: the output byte rate was not recalculated, so audio-video sync was simply broken. Fix this by calculating the byte rate on the fly, instead of storing it in sh_audio. Format changes are relatively common (switches between stereo and 5.1 in TV recordings), so this fixes a somewhat critical bug. --- stream/tv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'stream/tv.c') diff --git a/stream/tv.c b/stream/tv.c index e5768a350a..72b67b7f9e 100644 --- a/stream/tv.c +++ b/stream/tv.c @@ -794,7 +794,7 @@ static demuxer_t* demux_open_tv(demuxer_t *demuxer) sh_audio->gsh->codec = "mp-pcm"; sh_audio->format = audio_format; - sh_audio->i_bps = sh_audio->o_bps = + sh_audio->i_bps = sh_audio->samplerate * sh_audio->samplesize * sh_audio->channels.num; -- cgit v1.2.3 From fa74be880c27b350615f62dd4a0d6a32be56c60e Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 11 Jul 2013 19:17:05 +0200 Subject: tv: add hack in preparation of demux_stream removal Currently, all demuxer fill_buffer functions have a demux_stream parameter. We want to remove that, but the TV code still depends on it. Add a hack to remove that dependency. The problem with the TV code is that reading video and audio frames blocks, so in order to avoid a deadlock, you should read either of them only if the decoder actually requests new data. --- stream/tv.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'stream/tv.c') diff --git a/stream/tv.c b/stream/tv.c index 72b67b7f9e..0f09bb3448 100644 --- a/stream/tv.c +++ b/stream/tv.c @@ -215,10 +215,23 @@ static int demux_tv_fill_buffer(demuxer_t *demux, demux_stream_t *ds) tvi_handle_t *tvh=(tvi_handle_t*)(demux->priv); demux_packet_t* dp; unsigned int len=0; + struct sh_stream *want_audio = NULL, *want_video = NULL; + + for (int n = 0; n < demux->num_streams; n++) { + struct sh_stream *sh = demux->streams[n]; + if (!demuxer_stream_has_packets_queued(demux, sh) && + demuxer_stream_is_selected(demux, sh)) + { + if (sh->type == STREAM_AUDIO) + want_audio = sh; + if (sh->type == STREAM_VIDEO) + want_video = sh; + } + } /* ================== ADD AUDIO PACKET =================== */ - if (ds==demux->audio && tvh->tv_param->noaudio == 0 && + if (want_audio && tvh->tv_param->noaudio == 0 && tvh->functions->control(tvh->priv, TVI_CONTROL_IS_AUDIO, 0) == TVI_CONTROL_TRUE) { @@ -227,19 +240,19 @@ static int demux_tv_fill_buffer(demuxer_t *demux, demux_stream_t *ds) dp=new_demux_packet(len); dp->keyframe = true; dp->pts=tvh->functions->grab_audio_frame(tvh->priv, dp->buffer,len); - ds_add_packet(demux->audio,dp); + demuxer_add_packet(demux, want_audio, dp); } /* ================== ADD VIDEO PACKET =================== */ - if (ds==demux->video && tvh->functions->control(tvh->priv, + if (want_video && tvh->functions->control(tvh->priv, TVI_CONTROL_IS_VIDEO, 0) == TVI_CONTROL_TRUE) { len = tvh->functions->get_video_framesize(tvh->priv); dp=new_demux_packet(len); dp->keyframe = true; dp->pts=tvh->functions->grab_video_frame(tvh->priv, dp->buffer, len); - ds_add_packet(demux->video,dp); + demuxer_add_packet(demux, want_video, dp); } if (tvh->tv_param->scan) tv_scan(tvh); -- cgit v1.2.3 From 6ede485e4b2ea1093e84d8589a1c321fe8a8462a Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 11 Jul 2013 19:17:51 +0200 Subject: core: don't access demux_stream outside of demux.c, make it private Generally remove all accesses to demux_stream from all the code, except inside of demux.c. Make it completely private to demux.c. This simplifies the code because it removes an extra concept. In demux.c it is reduced to a simple packet queue. There were other uses of demux_stream, but they were removed or are removed with this commit. Remove the extra "ds" argument to demux fill_buffer callback. It was used by demux_avi and the TV pseudo-demuxer only. Remove usage of d_video->last_pts from the no-correct-pts code. This field contains the last PTS retrieved after a packet that is not NOPTS. We can easily get this value manually because we read the packets ourselves. Reuse sh_video->last_pts to store the packet PTS values. It was used only by the correct-pts code before, and like d_video->last_pts, it is reset on seek. The behavior should be exactly the same. --- stream/tv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'stream/tv.c') diff --git a/stream/tv.c b/stream/tv.c index 0f09bb3448..93c50fb36a 100644 --- a/stream/tv.c +++ b/stream/tv.c @@ -210,7 +210,7 @@ static void tv_scan(tvi_handle_t *tvh) */ /* fill demux->video and demux->audio */ -static int demux_tv_fill_buffer(demuxer_t *demux, demux_stream_t *ds) +static int demux_tv_fill_buffer(demuxer_t *demux) { tvi_handle_t *tvh=(tvi_handle_t*)(demux->priv); demux_packet_t* dp; -- cgit v1.2.3 From a6706c41d8d89bc1a72dd21e215885e79a766db2 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 11 Jul 2013 19:21:45 +0200 Subject: video: eliminate frametime variable --- stream/tv.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'stream/tv.c') diff --git a/stream/tv.c b/stream/tv.c index 93c50fb36a..2c930781bc 100644 --- a/stream/tv.c +++ b/stream/tv.c @@ -743,8 +743,6 @@ static demuxer_t* demux_open_tv(demuxer_t *demuxer) if (tvh->tv_param->fps != -1.0f) sh_video->fps = tvh->tv_param->fps; - sh_video->frametime = 1.0f/sh_video->fps; - /* If playback only mode, go to immediate mode, fail silently */ if(tvh->tv_param->immediate == 1) { -- cgit v1.2.3 From d17d2fdc7c536821b3fea8c4a37c0ad09fc487db Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 11 Jul 2013 20:08:12 +0200 Subject: demux: change signature of open functions, cleanups Preparation for redoing the open functions. --- stream/tv.c | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) (limited to 'stream/tv.c') diff --git a/stream/tv.c b/stream/tv.c index 2c930781bc..aa5383402f 100644 --- a/stream/tv.c +++ b/stream/tv.c @@ -701,7 +701,7 @@ static int tv_uninit(tvi_handle_t *tvh) return res; } -static demuxer_t* demux_open_tv(demuxer_t *demuxer) +static int demux_open_tv(demuxer_t *demuxer) { tvi_handle_t *tvh; sh_video_t *sh_video; @@ -709,14 +709,14 @@ static demuxer_t* demux_open_tv(demuxer_t *demuxer) const tvi_functions_t *funcs; demuxer->priv=NULL; - if(!(tvh=tv_begin(demuxer->stream->priv))) return NULL; - if (!tvh->functions->init(tvh->priv)) return NULL; + if(!(tvh=tv_begin(demuxer->stream->priv))) return -1; + if (!tvh->functions->init(tvh->priv)) return -1; tvh->demuxer = demuxer; if (!open_tv(tvh)){ tv_uninit(tvh); - return NULL; + return -1; } funcs = tvh->functions; demuxer->priv=tvh; @@ -827,7 +827,7 @@ no_audio: if(!(funcs->start(tvh->priv))){ // start failed :( tv_uninit(tvh); - return NULL; + return -1; } /* set color eq */ @@ -840,7 +840,7 @@ no_audio: if(funcs->control(tvh->priv,TVI_CONTROL_VID_SET_GAIN,&tvh->tv_param->gain)!=TVI_CONTROL_TRUE) mp_msg(MSGT_TV,MSGL_WARN,"Unable to set gain control!\n"); - return demuxer; + return 0; } static void demux_close_tv(demuxer_t *demuxer) @@ -1094,17 +1094,13 @@ int tv_step_chanlist(tvi_handle_t *tvh) } demuxer_desc_t demuxer_desc_tv = { - "Tv card demuxer", - "tv", - "TV", - "Alex Beregszaszi, Charles R. Henrich", - "?", - DEMUXER_TYPE_TV, - 0, // no autodetect - NULL, - demux_tv_fill_buffer, - demux_open_tv, - demux_close_tv, - NULL, - NULL + .info = "Tv card demuxer", + .name = "tv", + .shortdesc = "TV", + .author = "Alex Beregszaszi, Charles R. Henrich", + .comment = "?", + .type = DEMUXER_TYPE_TV, + .fill_buffer = demux_tv_fill_buffer, + .open = demux_open_tv, + .close = demux_close_tv, }; -- cgit v1.2.3 From 3269bd178020c5d821e8b2d1fd807a38d63e93ce Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 12 Jul 2013 21:58:11 +0200 Subject: demux: rewrite probing and demuxer initialization Get rid of the strange and messy reliance on DEMUXER_TYPE_ constants. Instead of having two open functions for the demuxer callbacks (which somehow are both optional, but you can also decide to implement both...), just have one function. This function takes a parameter that tells the demuxer how strictly it should check for the file headers. This is a nice simplification and allows more flexibility. Remove the file extension code. This literally did nothing (anymore). Change demux_lavf so that we check our other builtin demuxers first before libavformat tries to guess by file extension. --- stream/tv.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'stream/tv.c') diff --git a/stream/tv.c b/stream/tv.c index aa5383402f..9ddf3771ed 100644 --- a/stream/tv.c +++ b/stream/tv.c @@ -701,13 +701,16 @@ static int tv_uninit(tvi_handle_t *tvh) return res; } -static int demux_open_tv(demuxer_t *demuxer) +static int demux_open_tv(demuxer_t *demuxer, enum demux_check check) { tvi_handle_t *tvh; sh_video_t *sh_video; sh_audio_t *sh_audio = NULL; const tvi_functions_t *funcs; + if (check > DEMUX_CHECK_REQUEST || demuxer->stream->type != STREAMTYPE_TV) + return -1; + demuxer->priv=NULL; if(!(tvh=tv_begin(demuxer->stream->priv))) return -1; if (!tvh->functions->init(tvh->priv)) return -1; -- cgit v1.2.3 From 6c414f8c7a66ce3bb0c2446cb7fb0fb802a9e98b Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 12 Jul 2013 22:12:02 +0200 Subject: demux: remove useless author/comment fields Same deal as with previous commit. --- stream/tv.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'stream/tv.c') diff --git a/stream/tv.c b/stream/tv.c index 9ddf3771ed..9b1f8024e4 100644 --- a/stream/tv.c +++ b/stream/tv.c @@ -1097,11 +1097,8 @@ int tv_step_chanlist(tvi_handle_t *tvh) } demuxer_desc_t demuxer_desc_tv = { - .info = "Tv card demuxer", .name = "tv", - .shortdesc = "TV", - .author = "Alex Beregszaszi, Charles R. Henrich", - .comment = "?", + .desc = "TV card demuxer", .type = DEMUXER_TYPE_TV, .fill_buffer = demux_tv_fill_buffer, .open = demux_open_tv, -- cgit v1.2.3