From abc8d3661e0865840a99cb76a17ad9d9b185ded9 Mon Sep 17 00:00:00 2001 From: martii Date: Sat, 5 Apr 2014 11:36:49 +0200 Subject: [PATCH] libeplayer3: move width/height/framerate/timescale calculation to writers --- libeplayer3/container/container_ffmpeg.c | 53 +----------------------- libeplayer3/include/manager.h | 12 +----- libeplayer3/include/output.h | 6 --- libeplayer3/include/writer.h | 5 --- libeplayer3/output/linuxdvb.c | 12 +----- libeplayer3/output/writer/divx.c | 3 +- libeplayer3/output/writer/h264.c | 8 ++-- libeplayer3/output/writer/vc1.c | 25 +++++------ libeplayer3/output/writer/wmv.c | 8 ++-- 9 files changed, 27 insertions(+), 105 deletions(-) diff --git a/libeplayer3/container/container_ffmpeg.c b/libeplayer3/container/container_ffmpeg.c index 538e120..4eadd19 100644 --- a/libeplayer3/container/container_ffmpeg.c +++ b/libeplayer3/container/container_ffmpeg.c @@ -377,10 +377,7 @@ static void FFMPEGThread(Context_t * context) avOut.data = packet_data; avOut.len = packet_size; avOut.pts = pts; - avOut.frameRate = videoTrack->frame_rate; - avOut.timeScale = videoTrack->TimeScale; - avOut.width = videoTrack->width; - avOut.height = videoTrack->height; + avOut.type = "video"; avOut.stream = videoTrack->stream; avOut.avfc = avContext; @@ -404,10 +401,6 @@ static void FFMPEGThread(Context_t * context) avOut.data = packet_data; avOut.len = packet_size; avOut.pts = pts; - avOut.frameRate = 0; - avOut.timeScale = 0; - avOut.width = 0; - avOut.height = 0; avOut.type = "audio"; avOut.stream = audioTrack->stream; avOut.avfc = avContext; @@ -527,10 +520,6 @@ static void FFMPEGThread(Context_t * context) avOut.len = out_samples * sizeof(short) * out_channels; avOut.pts = videoTrack ? pts : 0; - avOut.frameRate = 0; - avOut.timeScale = 0; - avOut.width = 0; - avOut.height = 0; avOut.type = "audio"; avOut.stream = audioTrack->stream; avOut.avfc = avContext; @@ -543,10 +532,6 @@ static void FFMPEGThread(Context_t * context) avOut.data = packet_data; avOut.len = packet_size; avOut.pts = pts; - avOut.frameRate = 0; - avOut.timeScale = 0; - avOut.width = 0; - avOut.height = 0; avOut.type = "audio"; avOut.stream = audioTrack->stream; avOut.avfc = avContext; @@ -873,38 +858,6 @@ int container_ffmpeg_update_tracks(Context_t * context, char *filename) ffmpeg_printf(10, "CODEC_TYPE_VIDEO %d\n", stream->codec->codec_type); if (encoding != NULL) { - track.type = eTypeES; - track.version = version; - - track.width = stream->codec->width; - track.height = stream->codec->height; - - track.frame_rate = stream->r_frame_rate.num; - - double frame_rate = av_q2d(stream->r_frame_rate); /* rational to double */ - - ffmpeg_printf(10, "frame_rate = %f\n", frame_rate); - - track.frame_rate = frame_rate * 1000.0; - - /* fixme: revise this */ - - if (track.frame_rate < 23970) - track.TimeScale = 1001; - else - track.TimeScale = 1000; - - ffmpeg_printf(20, "bit_rate = %d\n", stream->codec->bit_rate); - ffmpeg_printf(20, "flags = %d\n", stream->codec->flags); - ffmpeg_printf(20, "frame_bits = %d\n", stream->codec->frame_bits); - ffmpeg_printf(20, "time_base.den %d\n", stream->time_base.den); - ffmpeg_printf(20, "time_base.num %d\n", stream->time_base.num); - ffmpeg_printf(20, "frame_rate %d\n", stream->r_frame_rate.num); - ffmpeg_printf(20, "TimeScale %d\n", stream->r_frame_rate.den); - - ffmpeg_printf(20, "frame_rate %d\n", track.frame_rate); - ffmpeg_printf(20, "TimeScale %d\n", track.TimeScale); - track.Name = "und"; track.Encoding = encoding; track.avfc = avContext; @@ -932,7 +885,6 @@ int container_ffmpeg_update_tracks(Context_t * context, char *filename) if (encoding != NULL) { AVDictionaryEntry *lang; - track.type = eTypeES; lang = av_dict_get(stream->metadata, "language", NULL, 0); @@ -988,9 +940,6 @@ int container_ffmpeg_update_tracks(Context_t * context, char *filename) track.have_aacheader = -1; #endif - track.width = -1; /* will be filled online from videotrack */ - track.height = -1; /* will be filled online from videotrack */ - ffmpeg_printf(10, "subtitle codec %d\n", stream->codec->codec_id); ffmpeg_printf(10, "subtitle width %d\n", stream->codec->width); ffmpeg_printf(10, "subtitle height %d\n", stream->codec->height); diff --git a/libeplayer3/include/manager.h b/libeplayer3/include/manager.h index a96c387..8a8c543 100644 --- a/libeplayer3/include/manager.h +++ b/libeplayer3/include/manager.h @@ -38,16 +38,8 @@ typedef struct Track_s { char *language; /* length of track */ - long long int duration; - unsigned int frame_rate; - unsigned int TimeScale; - int version; - long long int pts; - - /* for later use: */ - eTrackTypeEplayer type; - int width; - int height; + uint64_t duration; + uint64_t pts; /* context from ffmpeg */ AVFormatContext *avfc; diff --git a/libeplayer3/include/output.h b/libeplayer3/include/output.h index 3e6e33d..2e9f459 100644 --- a/libeplayer3/include/output.h +++ b/libeplayer3/include/output.h @@ -45,12 +45,6 @@ typedef struct { uint64_t pts; - float frameRate; - unsigned int timeScale; - - unsigned int width; - unsigned int height; - char *type; /* context from ffmpeg */ diff --git a/libeplayer3/include/writer.h b/libeplayer3/include/writer.h index 65a58f2..9a0c10d 100644 --- a/libeplayer3/include/writer.h +++ b/libeplayer3/include/writer.h @@ -21,11 +21,6 @@ typedef struct { int uSampleRate; int uBitsPerSample; int bLittleEndian; - unsigned int FrameRate; - unsigned int FrameScale; - unsigned int Width; - unsigned int Height; - unsigned char Version; /* context from ffmpeg */ AVFormatContext *avfc; /* stream from ffmpeg */ diff --git a/libeplayer3/output/linuxdvb.c b/libeplayer3/output/linuxdvb.c index 78bb0ab..aa29508 100644 --- a/libeplayer3/output/linuxdvb.c +++ b/libeplayer3/output/linuxdvb.c @@ -913,9 +913,7 @@ static int Write(Context_t *context, AudioVideoOut_t *out) video = !strcmp("video", out->type); audio = !strcmp("audio", out->type); - linuxdvb_printf(20, - "DataLength=%u Pts=%llu FrameRate=%f\n", - out->len, out->pts, out->frameRate); + linuxdvb_printf(20, "DataLength=%u Pts=%llu\n", out->len, out->pts); linuxdvb_printf(20, "v%d a%d\n", video, audio); if (video) { @@ -942,11 +940,6 @@ static int Write(Context_t *context, AudioVideoOut_t *out) call.data = out->data; call.len = out->len; call.Pts = out->pts; - call.FrameRate = out->frameRate; - call.FrameScale = out->timeScale; - call.Width = out->width; - call.Height = out->height; - call.Version = 0; // is unsingned char if (writer->writeData) res = writer->writeData(&call); @@ -984,9 +977,6 @@ static int Write(Context_t *context, AudioVideoOut_t *out) call.data = out->data; call.len = out->len; call.Pts = out->pts; - call.FrameRate = out->frameRate; - call.FrameScale = out->timeScale; - call.Version = 0; /* -1; unsigned char cannot be negative */ call.uNoOfChannels = out->uNoOfChannels; call.uSampleRate = out->uSampleRate; diff --git a/libeplayer3/output/writer/divx.c b/libeplayer3/output/writer/divx.c index eec6931..08608fc 100644 --- a/libeplayer3/output/writer/divx.c +++ b/libeplayer3/output/writer/divx.c @@ -121,7 +121,8 @@ static int writeData(WriterAVCallData_t *call) divx_printf(10, "AudioPts %lld\n", call->Pts); - usecPerFrame = 1000000000 / call->FrameRate; + usecPerFrame = 1000000 / av_q2d(call->stream->r_frame_rate); + divx_printf(10, "Microsecends per frame = %d\n", usecPerFrame); memset(FakeHeaders, 0, sizeof(FakeHeaders)); diff --git a/libeplayer3/output/writer/h264.c b/libeplayer3/output/writer/h264.c index 32bff85..3a845c8 100644 --- a/libeplayer3/output/writer/h264.c +++ b/libeplayer3/output/writer/h264.c @@ -124,8 +124,9 @@ static int writeData(WriterAVCallData_t *call) return 0; } - TimeDelta = call->FrameRate; - TimeScale = call->FrameScale; + TimeDelta = 1000.0 * av_q2d(call->stream->r_frame_rate); /* rational to double */ + TimeScale = (TimeDelta < 23970) ? 1001 : 1000; /* fixme: revise this */ + VideoPts = call->Pts; h264_printf(10, "VideoPts %lld - %d %d\n", call->Pts, TimeDelta, @@ -148,8 +149,7 @@ static int writeData(WriterAVCallData_t *call) || (call->data[0] == 0xff && call->data[1] == 0xff && call->data[2] == 0xff && call->data[3] == 0xff))) { unsigned int PacketLength = 0; - unsigned int FakeStartCode = - (call->Version << 8) | PES_VERSION_FAKE_START_CODE; + unsigned int FakeStartCode = /* (call->Version << 8) | */ PES_VERSION_FAKE_START_CODE; iov[ic++].iov_base = PesHeader; if (initialHeader) { initialHeader = 0; diff --git a/libeplayer3/output/writer/vc1.c b/libeplayer3/output/writer/vc1.c index ab0bf73..34d378f 100644 --- a/libeplayer3/output/writer/vc1.c +++ b/libeplayer3/output/writer/vc1.c @@ -155,11 +155,12 @@ static int writeData(WriterAVCallData_t *call) unsigned int crazyFramerate = 0; struct iovec iov[2]; - vc1_printf(10, "Framerate: %u\n", call->FrameRate); - vc1_printf(10, "biWidth: %d\n", call->Width); - vc1_printf(10, "biHeight: %d\n", call->Height); + vc1_printf(10, "Framerate: %f\n", 1000.0 * av_q2d(call->stream->r_frame_rate)); + vc1_printf(10, "biWidth: %d\n", call->stream->codec->width); + vc1_printf(10, "biHeight: %d\n", call->stream->codec->height); + + crazyFramerate = ((10000000.0 / av_q2d(call->stream->r_frame_rate))); - crazyFramerate = ((10000000.0 / call->FrameRate) * 1000.0); vc1_printf(10, "crazyFramerate: %u\n", crazyFramerate); memset(PesPayload, 0, sizeof(PesPayload)); @@ -175,14 +176,14 @@ static int writeData(WriterAVCallData_t *call) PesPtr += WMV3_PRIVATE_DATA_LENGTH; /* Metadata Header Struct A */ - *PesPtr++ = (call->Height >> 0) & 0xff; - *PesPtr++ = (call->Height >> 8) & 0xff; - *PesPtr++ = (call->Height >> 16) & 0xff; - *PesPtr++ = call->Height >> 24; - *PesPtr++ = (call->Width >> 0) & 0xff; - *PesPtr++ = (call->Width >> 8) & 0xff; - *PesPtr++ = (call->Width >> 16) & 0xff; - *PesPtr++ = call->Width >> 24; + *PesPtr++ = (call->stream->codec->height >> 0) & 0xff; + *PesPtr++ = (call->stream->codec->height >> 8) & 0xff; + *PesPtr++ = (call->stream->codec->height >> 16) & 0xff; + *PesPtr++ = call->stream->codec->height >> 24; + *PesPtr++ = (call->stream->codec->width >> 0) & 0xff; + *PesPtr++ = (call->stream->codec->width >> 8) & 0xff; + *PesPtr++ = (call->stream->codec->width >> 16) & 0xff; + *PesPtr++ = call->stream->codec->width >> 24; PesPtr += 12; /* Skip flag word and Struct B first 8 bytes */ diff --git a/libeplayer3/output/writer/wmv.c b/libeplayer3/output/writer/wmv.c index 72294ae..5f16315 100644 --- a/libeplayer3/output/writer/wmv.c +++ b/libeplayer3/output/writer/wmv.c @@ -145,9 +145,10 @@ static int writeData(WriterAVCallData_t *call) memcpy(private_data.privateData, call->stream->codec->extradata, call->stream->codec->extradata_size > WMV3_PRIVATE_DATA_LENGTH ? WMV3_PRIVATE_DATA_LENGTH : call->stream->codec->extradata_size); - private_data.width = call->Width; - private_data.height = call->Height; - private_data.framerate = call->FrameRate; + private_data.width = call->stream->codec->width; + private_data.height = call->stream->codec->height; + private_data.framerate = 1000.0 * av_q2d(call->stream->r_frame_rate); /* rational to double */ + #define PES_MIN_HEADER_SIZE 9 if (initialHeader) { @@ -156,7 +157,6 @@ static int writeData(WriterAVCallData_t *call) unsigned int MetadataLength; unsigned int crazyFramerate = 0; - wmv_printf(10, "Framerate: %u\n", private_data.framerate); wmv_printf(10, "biWidth: %d\n", private_data.width); wmv_printf(10, "biHeight: %d\n", private_data.height);