Skip to content

Commit

Permalink
Remove VideoSwitch parameter with some cleanups.
Browse files Browse the repository at this point in the history
  • Loading branch information
rofafor committed Jul 21, 2018
1 parent cb659cc commit 05c7de2
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 54 deletions.
2 changes: 1 addition & 1 deletion audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ static int AlsaThread(void)
}
// wait for space in kernel buffers
if ((err = snd_pcm_wait(AlsaPCMHandle, 24)) < 0) {
Error("audio/alsa: wait underrun error? '%s'", snd_strerror(err));
Debug("audio/alsa: wait underrun error? '%s'", snd_strerror(err));
err = snd_pcm_recover(AlsaPCMHandle, err, 0);
if (err >= 0) {
continue;
Expand Down
18 changes: 8 additions & 10 deletions codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -450,15 +450,14 @@ void CodecVideoFlushBuffers(VideoDecoder * decoder)
**
** @param decoder video decoder data
*/
const char* CodecVideoGetCodecName(VideoDecoder * decoder)
const char *CodecVideoGetCodecName(VideoDecoder * decoder)
{
if (decoder && decoder->VideoCodec)
return avcodec_get_name(decoder->VideoCodec->id);

return avcodec_get_name(AV_CODEC_ID_NONE);
}


//----------------------------------------------------------------------------
// Audio
//----------------------------------------------------------------------------
Expand Down Expand Up @@ -567,7 +566,7 @@ void CodecAudioOpen(AudioDecoder * audio_decoder, int codec_id_old)
switch (device_get_atype()) {
case 0:
break;
case 0x3: /* FALLTHRU */
case 0x3: /* FALLTHRU */
case 0x4:
codec_id = AV_CODEC_ID_MP2;
break;
Expand Down Expand Up @@ -600,7 +599,7 @@ void CodecAudioOpen(AudioDecoder * audio_decoder, int codec_id_old)
audio_decoder->AudioFmtCtx->audio_codec_id = codec_id;

av_dict_set_int(&options, "analyzeduration", 500, 0);
av_dict_set_int(&options, "probesize", alloc_size / 2 , 0);
av_dict_set_int(&options, "probesize", alloc_size / 2, 0);

input_format = av_find_input_format("mpeg");
if (!input_format) {
Expand All @@ -622,21 +621,18 @@ void CodecAudioOpen(AudioDecoder * audio_decoder, int codec_id_old)
Error("codec: failed to add audio stream to context");
goto error_avformat_new_stream;
}

#if 1
audio_decoder->AudioFmtCtx->streams[0]->codecpar->codec_id = codec_id;
audio_decoder->AudioFmtCtx->streams[0]->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
#endif
#if 1

ret = avformat_find_stream_info(audio_decoder->AudioFmtCtx, NULL);
if (ret < 0) {
Error("codec: can't find audio stream info: %s", av_err2str(ret));
goto error_avformat_find_stream_info;
}
#endif

av_dump_format(audio_decoder->AudioFmtCtx, 0, "vaapidevice audio", 0);
#if 0
//#define AVFORMAT_FIND_BEST_AUDIO_STREAM
#ifdef AVFORMAT_FIND_BEST_AUDIO_STREAM
ret = av_find_best_stream(audio_decoder->AudioFmtCtx, AVMEDIA_TYPE_AUDIO, -1, -1, &audio_codec, 0);
if (ret < 0) {
Error("codec: can't find best audio stream: %s", av_err2str(ret));
Expand Down Expand Up @@ -704,7 +700,9 @@ void CodecAudioOpen(AudioDecoder * audio_decoder, int codec_id_old)
error_avcodec_alloc_context3:
error_avcodec_find_decoder:
error_avformat_new_stream:
#ifdef AVFORMAT_FIND_BEST_AUDIO_STREAM
error_avformat_find_best_stream:
#endif
error_avformat_find_stream_info:
error_avformat_open_input:
av_freep(avio_ctx);
Expand Down
2 changes: 1 addition & 1 deletion codec.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ extern void CodecVideoDecode(VideoDecoder *);
extern void CodecVideoFlushBuffers(VideoDecoder *);

/// Get video decoder name.
extern const char* CodecVideoGetCodecName(VideoDecoder *);
extern const char *CodecVideoGetCodecName(VideoDecoder *);

/// Allocate a new audio decoder context.
extern AudioDecoder *CodecAudioNewDecoder(void);
Expand Down
10 changes: 1 addition & 9 deletions vaapidev.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include "video.h"
#include "codec.h"


//////////////////////////////////////////////////////////////////////////////
// Variables
//////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -482,11 +481,6 @@ struct __video_stream__

static VideoStream MyVideoStream[1]; ///< normal video stream

#ifdef DEBUG
uint32_t VideoSwitch; ///< debug video switch ticks
static int VideoMaxPacketSize; ///< biggest used packet buffer
#endif

const char *X11DisplayName; ///< x11 display name
static volatile char Usr1Signal; ///< true got usr1 signal

Expand Down Expand Up @@ -1473,9 +1467,6 @@ int Start(void)
*/
void Stop(void)
{
#ifdef DEBUG
Debug1("video: max used PES packet size: %d", VideoMaxPacketSize);
#endif
}

/**
Expand Down Expand Up @@ -1613,6 +1604,7 @@ char *GetVideoStats(void)
char *GetVideoInfo(void)
{
const char *codec = CodecVideoGetCodecName(MyVideoStream->Decoder);

return MyVideoStream->HwDecoder ? VideoGetInfo(MyVideoStream->HwDecoder, codec) : NULL;
}

Expand Down
12 changes: 7 additions & 5 deletions vaapidevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1979,6 +1979,7 @@ void cVaapiDevice::GetOsdSize(int &width, int &height, double &pixel_aspect)
int cVaapiDevice::PlayAudio(const uchar * data, int length, uchar id)
{
const int ringBufferSize = KILOBYTE(512);

if (length > ringBufferSize) {
Error("Audio PES packet size (%d) too large for frame ringbuffer", length);
return 0;
Expand All @@ -1993,6 +1994,7 @@ int cVaapiDevice::PlayAudio(const uchar * data, int length, uchar id)
if (audioEof || !audioBuffer->Put(packet)) {
// If this happens often enough vdr will start asking for a clear of device
delete packet;

return 0;
}
// TODO: remove vaapidev code
Expand Down Expand Up @@ -2040,6 +2042,7 @@ void cVaapiDevice::SetVolumeDevice(int volume)
int cVaapiDevice::PlayVideo(const uchar * data, int length)
{
const int ringBufferSize = MEGABYTE(1);

if (length > ringBufferSize) {
Error("Video PES packet size (%d) too large for frame ringbuffer", length);
return 0;
Expand All @@ -2054,6 +2057,7 @@ int cVaapiDevice::PlayVideo(const uchar * data, int length)
if (videoEof || !videoBuffer->Put(packet)) {
// If this happens often enough vdr will start asking for a clear of device
delete packet;

return 0;
}

Expand Down Expand Up @@ -2118,10 +2122,9 @@ int cVaapiDevice::DeviceGetAtype()
eTrackType track = GetCurrentAudioTrack();

if (IS_AUDIO_TRACK(track)) {
return PatPmtParser()->Atype(int(track - ttAudioFirst));
}
else if (IS_DOLBY_TRACK(track)) {
return PatPmtParser()->Dtype(int(track - ttDolbyFirst));
return PatPmtParser()->Atype(int (track - ttAudioFirst));
} else if (IS_DOLBY_TRACK(track)) {
return PatPmtParser()->Dtype(int (track - ttDolbyFirst));
}

return -1;
Expand Down Expand Up @@ -2203,7 +2206,6 @@ int cVaapiDevice::DeviceAudioReadCallback(uchar * data, int size)

} while (!packet && ffmpegMode == 0 && retries++ < 3);


if (!packet) {
return ffmpegMode ? 0 : AVERROR_EOF;
}
Expand Down
50 changes: 22 additions & 28 deletions video.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,6 @@ static xcb_atom_t WmDeleteWindowAtom; ///< WM delete message atom
static xcb_atom_t NetWmState; ///< wm-state message atom
static xcb_atom_t NetWmStateFullscreen; ///< fullscreen wm-state message atom

#ifdef DEBUG
extern uint32_t VideoSwitch; ///< ticks for channel switch
#endif
extern void AudioVideoReady(int64_t); ///< tell audio video is ready
extern int IsReplay(void);

Expand Down Expand Up @@ -366,7 +363,6 @@ static void VideoSetPts(int64_t * pts_p, int interlaced, const AVCodecContext *
// update video clock
if (*pts_p != (int64_t) AV_NOPTS_VALUE) {
*pts_p += duration * 90;
//Info("video: %s +pts", Timestamp2String(*pts_p));
}
//av_opt_ptr(avcodec_get_frame_class(), frame, "best_effort_timestamp");
//pts = frame->best_effort_timestamp;
Expand Down Expand Up @@ -1354,6 +1350,11 @@ static VaapiDecoder *VaapiNewHwDecoder(VideoStream * stream)
decoder->LastAudioPTS = 0;
decoder->SyncCounter = 0;
decoder->StartCounter = 0;
decoder->FramesDuped = 0;
decoder->FramesMissed = 0;
decoder->FramesDropped = 0;
decoder->FrameCounter = 0;
decoder->FramesDisplayed = 0;

VaapiDecoders[VaapiDecoderN++] = decoder;

Expand Down Expand Up @@ -1440,9 +1441,12 @@ static void VaapiCleanup(VaapiDecoder * decoder)
decoder->PostProcSurfaceWrite = 0;

decoder->SyncCounter = 0;
decoder->StartCounter = 0;
decoder->FramesDuped = 0;
decoder->FramesMissed = 0;
decoder->FramesDropped = 0;
decoder->FrameCounter = 0;
decoder->FramesDisplayed = 0;
decoder->StartCounter = 0;
decoder->Closing = 0;
decoder->PTS = AV_NOPTS_VALUE;
VideoDeltaPTS = 0;
Expand Down Expand Up @@ -3615,7 +3619,8 @@ char *VaapiGetStats(VaapiDecoder * decoder)
if (snprintf(&buffer[0], sizeof(buffer),
" Frames: missed(%d) duped(%d) dropped(%d) total(%d) PTS(%s) drift(%" PRId64 ") audio(%" PRId64 ") video(%"
PRId64 ")", decoder->FramesMissed, decoder->FramesDuped, decoder->FramesDropped, decoder->FrameCounter,
Timestamp2String(video_clock), (video_clock - audio_clock) / 90, AudioGetDelay() / 90, VideoDeltaPTS / 90)) {
Timestamp2String(video_clock), (video_clock - audio_clock) / 90, AudioGetDelay() / 90,
VideoDeltaPTS / 90)) {
return strdup(buffer);
}

Expand Down Expand Up @@ -3730,7 +3735,7 @@ static void VaapiSyncDecoder(VaapiDecoder * decoder)

// Calc correct diff
err = VaapiMessage(1, "AV-PTS Rollover, correcting AV-PTS Difference");
diff = (video_clock - audio_clock - (int64_t) VideoAudioDelay);
diff = video_clock - audio_clock - (int64_t) VideoAudioDelay;
}
// Low-Pass Filter AV-PTS-Diff, if in Sync-Range of +/- 250 ms
if (abs(diff) < (int64_t) 250 * 90) {
Expand Down Expand Up @@ -3762,11 +3767,7 @@ static void VaapiSyncDecoder(VaapiDecoder * decoder)
}
#if defined(DEBUG) || defined(AV_INFO)
if (!decoder->SyncCounter && decoder->StartCounter < 1000) {
#ifdef DEBUG
Debug7("video/vaapi: synced after %d frames %dms", decoder->StartCounter, GetMsTicks() - VideoSwitch);
#else
Info("video/vaapi: synced after %d frames", decoder->StartCounter);
#endif
decoder->StartCounter += 1000;
}
#endif
Expand All @@ -3779,7 +3780,7 @@ static void VaapiSyncDecoder(VaapiDecoder * decoder)
++decoder->FramesDuped;
// FIXME: don't warn after stream start, don't warn during pause
err =
VaapiMessage(0, "video: decoder buffer empty, duping frame (%u/%u) %d v-buf", decoder->FramesDuped,
VaapiMessage(0, "video: decoder buffer empty, duping frame (%d/%d) %d v-buf", decoder->FramesDuped,
decoder->FrameCounter, VideoGetBuffers(decoder->Stream));
// some time no new picture
if (decoder->Closing < -300) {
Expand All @@ -3798,11 +3799,13 @@ static void VaapiSyncDecoder(VaapiDecoder * decoder)
if (!err) {
VaapiMessage(0, NULL);
}
Info("video: %s%+5" PRId64 " %4" PRId64 " %3d/\\ms %3d%+d v-buf", Timestamp2String(video_clock),
(video_clock - audio_clock) / 90, AudioGetDelay() / 90, (int)VideoDeltaPTS / 90,
VideoGetBuffers(decoder->Stream), decoder->Interlaced ?
(2 * atomic_read(&decoder->SurfacesFilled) - decoder->SurfaceField) :
atomic_read(&decoder->SurfacesFilled));
if (audio_clock != (int64_t) AV_NOPTS_VALUE && video_clock != (int64_t) AV_NOPTS_VALUE) {
Info("video: %s%+5" PRId64 " %4" PRId64 " %3d/\\ms %3d%+d v-buf", Timestamp2String(video_clock),
(video_clock - audio_clock) / 90, AudioGetDelay() / 90, (int)VideoDeltaPTS / 90,
VideoGetBuffers(decoder->Stream),
decoder->Interlaced ? (2 * atomic_read(&decoder->SurfacesFilled) -
decoder->SurfaceField) : atomic_read(&decoder->SurfacesFilled));
}
if (!(decoder->FramesDisplayed % (5 * 60 * 60))) {
VaapiPrintFrames(decoder);
}
Expand Down Expand Up @@ -3844,12 +3847,6 @@ static void VaapiSyncDisplayFrame(void)
///
static void VaapiSyncRenderFrame(VaapiDecoder * decoder, const AVCodecContext * video_ctx, const AVFrame * frame)
{
#ifdef DEBUG
if (!atomic_read(&decoder->SurfacesFilled)) {
Debug7("video: new stream frame %dms", GetMsTicks() - VideoSwitch);
}
#endif

// if video output buffer is full, wait and display surface.
// loop for interlace
if (atomic_read(&decoder->SurfacesFilled) >= VIDEO_SURFACES_MAX - 1) {
Expand Down Expand Up @@ -4726,14 +4723,11 @@ enum AVPixelFormat Video_get_format(VideoHwDecoder * hw_decoder, AVCodecContext
const enum AVPixelFormat *fmt)
{
#ifdef DEBUG
int ms_delay;

// FIXME: use frame time
ms_delay = (1000 * video_ctx->time_base.num * video_ctx->ticks_per_frame)
int ms_delay = (1000 * video_ctx->time_base.num * video_ctx->ticks_per_frame)
/ video_ctx->time_base.den;

Debug7("video: ready %s %2dms/frame %dms", Timestamp2String(VideoGetClock(hw_decoder)), ms_delay,
GetMsTicks() - VideoSwitch);
Debug7("video: ready %s %2dms/frame", Timestamp2String(VideoGetClock(hw_decoder)), ms_delay);
#endif

return VideoUsedModule->get_format(hw_decoder, video_ctx, fmt);
Expand Down

0 comments on commit 05c7de2

Please sign in to comment.