diff --git a/libeplayer3/container/container_ffmpeg.c b/libeplayer3/container/container_ffmpeg.c index 8e35cb3..d108900 100644 --- a/libeplayer3/container/container_ffmpeg.c +++ b/libeplayer3/container/container_ffmpeg.c @@ -48,7 +48,9 @@ #include "common.h" #include "misc.h" #include "debug.h" +#if 0 #include "aac.h" +#endif #include "pcm.h" #include "ffmpeg_metadata.h" #include "subtitle.h" @@ -116,8 +118,7 @@ static float seek_sec_abs = -1.0, seek_sec_rel = 0.0; static char *Codec2Encoding(AVCodecContext * codec, int *version) { - fprintf(stderr, "Codec ID: %ld (%.8lx)\n", (long) codec->codec_id, - (long) codec->codec_id); + fprintf(stderr, "Codec ID: %ld (%.8lx)\n", (long) codec->codec_id, (long) codec->codec_id); switch (codec->codec_id) { case AV_CODEC_ID_MPEG1VIDEO: case AV_CODEC_ID_MPEG2VIDEO: @@ -201,8 +202,7 @@ static char *Codec2Encoding(AVCodecContext * codec, int *version) // Default to injected-pcm for unhandled audio types. if (codec->codec_type == AVMEDIA_TYPE_AUDIO) return "A_IPCM"; - ffmpeg_err("Codec ID %ld (%.8lx) not found\n", - (long) codec->codec_id, (long) codec->codec_id); + ffmpeg_err("Codec ID %ld (%.8lx) not found\n", (long) codec->codec_id, (long) codec->codec_id); } return NULL; } @@ -219,9 +219,7 @@ long long int calcPts(AVStream * stream, int64_t pts) else if (avContext->start_time == AV_NOPTS_VALUE) pts = 90000.0 * (double) pts *av_q2d(stream->time_base); else - pts = - 90000.0 * (double) pts *av_q2d(stream->time_base) - - 90000.0 * avContext->start_time / AV_TIME_BASE; + pts = 90000.0 * (double) pts *av_q2d(stream->time_base) - 90000.0 * avContext->start_time / AV_TIME_BASE; if (pts & 0x8000000000000000ull) pts = INVALID_PTS_VALUE; @@ -250,8 +248,7 @@ float getDurationFromSSALine(unsigned char *line) sscanf(ptr[2], "%d:%d:%d.%d", &h, &m, &s, &ms); msec = (ms * 10) + (s * 1000) + (m * 60 * 1000) + (h * 24 * 60 * 1000); sscanf(ptr[1], "%d:%d:%d.%d", &h, &m, &s, &ms); - msec -= - (ms * 10) + (s * 1000) + (m * 60 * 1000) + (h * 24 * 60 * 1000); + msec -= (ms * 10) + (s * 1000) + (m * 60 * 1000) + (h * 24 * 60 * 1000); ffmpeg_printf(10, "%s %s %f\n", ptr[2], ptr[1], (float) msec / 1000.0); @@ -270,9 +267,7 @@ static char *searchMeta(AVDictionary * metadata, char *ourTag) while (metadata_map[i] != NULL) { if (strcmp(ourTag, metadata_map[i]) == 0) { - while ((tag = - av_dict_get(metadata, "", tag, - AV_DICT_IGNORE_SUFFIX))) { + while ((tag = av_dict_get(metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) { if (strcmp(tag->key, metadata_map[i + 1]) == 0) { return tag->value; } @@ -297,8 +292,7 @@ static void FFMPEGThread(Context_t * context) hasPlayThreadStarted = 1; - int64_t currentVideoPts = -1, currentAudioPts = - -1, showtime = 0, bofcount = 0; + int64_t currentVideoPts = -1, currentAudioPts = -1, showtime = 0, bofcount = 0; AudioVideoOut_t avOut; SwrContext *swr = NULL; @@ -316,8 +310,7 @@ static void FFMPEGThread(Context_t * context) } ffmpeg_printf(10, "Running!\n"); - while (context && context->playback && context->playback->isPlaying - && !context->playback->abortRequested) { + while (context && context->playback && context->playback->isPlaying && !context->playback->abortRequested) { //IF MOVIE IS PAUSED, WAIT if (context->playback->isPaused) { @@ -332,21 +325,16 @@ static void FFMPEGThread(Context_t * context) if (seek_sec_rel != 0.0) { if (avContext->iformat->flags & AVFMT_TS_DISCONT) { - float br = (avContext->bit_rate) ? br = - avContext->bit_rate / 8.0 : 180000.0; + float br = (avContext->bit_rate) ? br = avContext->bit_rate / 8.0 : 180000.0; seek_target_flag = AVSEEK_FLAG_BYTE; seek_target = avio_tell(avContext->pb) + seek_sec_rel * br; } else { - seek_target = - ((((currentVideoPts > - 0) ? currentVideoPts : currentAudioPts) / - 90000.0) + seek_sec_rel) * AV_TIME_BASE; + seek_target = ((((currentVideoPts > 0) ? currentVideoPts : currentAudioPts) / 90000.0) + seek_sec_rel) * AV_TIME_BASE; } seek_sec_rel = 0.0; } else if (seek_sec_abs >= 0.0) { if (avContext->iformat->flags & AVFMT_TS_DISCONT) { - float br = (avContext->bit_rate) ? br = - avContext->bit_rate / 8.0 : 180000.0; + float br = (avContext->bit_rate) ? br = avContext->bit_rate / 8.0 : 180000.0; seek_target_flag = AVSEEK_FLAG_BYTE; seek_target = seek_sec_abs * br; } else { @@ -375,11 +363,7 @@ static void FFMPEGThread(Context_t * context) seek_target_flag = AVSEEK_FLAG_BYTE; } } else { - seek_target = - ((((currentVideoPts > - 0) ? currentVideoPts : currentAudioPts) / - 90000.0) + - context->playback->Speed * 8) * AV_TIME_BASE;; + seek_target = ((((currentVideoPts > 0) ? currentVideoPts : currentAudioPts) / 90000.0) + context->playback->Speed * 8) * AV_TIME_BASE;; } showtime = av_gettime() + 300000; //jump back every 300ms } else { @@ -390,9 +374,7 @@ static void FFMPEGThread(Context_t * context) int res; if (seek_target < 0) seek_target = 0; - res = - avformat_seek_file(avContext, -1, INT64_MIN, seek_target, - INT64_MAX, seek_target_flag); + res = avformat_seek_file(avContext, -1, INT64_MIN, seek_target, INT64_MAX, seek_target_flag); if (res < 0 && context->playback->BackWard) bofcount = 1; @@ -403,8 +385,7 @@ static void FFMPEGThread(Context_t * context) // flush streams unsigned int i; for (i = 0; i < avContext->nb_streams; i++) - if (avContext->streams[i]->codec - && avContext->streams[i]->codec->codec) + if (avContext->streams[i]->codec && avContext->streams[i]->codec->codec) avcodec_flush_buffers(avContext->streams[i]->codec); } @@ -432,39 +413,31 @@ static void FFMPEGThread(Context_t * context) int pid = avContext->streams[packet.stream_index]->id; - if (context->manager->video-> - Command(context, MANAGER_GET_TRACK, &videoTrack) < 0) + if (context->manager->video->Command(context, MANAGER_GET_TRACK, &videoTrack) < 0) ffmpeg_err("error getting video track\n"); - if (context->manager->audio-> - Command(context, MANAGER_GET_TRACK, &audioTrack) < 0) + if (context->manager->audio->Command(context, MANAGER_GET_TRACK, &audioTrack) < 0) ffmpeg_err("error getting audio track\n"); - if (context->manager->subtitle->Command(context, MANAGER_GET_TRACK, - &subtitleTrack) < 0) + if (context->manager->subtitle->Command(context, MANAGER_GET_TRACK, &subtitleTrack) < 0) ffmpeg_err("error getting subtitle track\n"); - if (context->manager->dvbsubtitle-> - Command(context, MANAGER_GET_TRACK, &dvbsubtitleTrack) < 0) + if (context->manager->dvbsubtitle->Command(context, MANAGER_GET_TRACK, &dvbsubtitleTrack) < 0) ffmpeg_err("error getting dvb subtitle track\n"); - if (context->manager->teletext->Command(context, MANAGER_GET_TRACK, - &teletextTrack) < 0) + if (context->manager->teletext->Command(context, MANAGER_GET_TRACK, &teletextTrack) < 0) ffmpeg_err("error getting teletext track\n"); - ffmpeg_printf(200, "packet.size %d - index %d\n", packet.size, - pid); + ffmpeg_printf(200, "packet.size %d - index %d\n", packet.size, pid); if (videoTrack && (videoTrack->Id == pid)) { - currentVideoPts = videoTrack->pts = pts = - calcPts(videoTrack->stream, packet.pts); + currentVideoPts = videoTrack->pts = pts = calcPts(videoTrack->stream, packet.pts); if ((currentVideoPts > latestPts) && (currentVideoPts != INVALID_PTS_VALUE)) latestPts = currentVideoPts; - ffmpeg_printf(200, "VideoTrack index = %d %lld\n", pid, - currentVideoPts); + ffmpeg_printf(200, "VideoTrack index = %d %lld\n", pid, currentVideoPts); avOut.data = packet.data; avOut.len = packet.size; @@ -481,192 +454,24 @@ static void FFMPEGThread(Context_t * context) ffmpeg_err("writing data to video device failed\n"); } } else if (audioTrack && (audioTrack->Id == pid)) { - currentAudioPts = audioTrack->pts = pts = - calcPts(audioTrack->stream, packet.pts); + if (!context->playback->BackWard) { + currentAudioPts = audioTrack->pts = pts = calcPts(audioTrack->stream, packet.pts); - if ((currentAudioPts > latestPts) && (!videoTrack)) - latestPts = currentAudioPts; + if ((currentAudioPts > latestPts) && (!videoTrack)) + latestPts = currentAudioPts; - ffmpeg_printf(200, "AudioTrack index = %d\n", pid); - if (audioTrack->inject_raw_pcm == 1) { - ffmpeg_printf(200, "write audio raw pcm\n"); - - pcmPrivateData_t extradata; - extradata.uNoOfChannels = - ((AVStream *) audioTrack->stream)->codec->channels; - extradata.uSampleRate = - ((AVStream *) audioTrack->stream)->codec->sample_rate; - extradata.uBitsPerSample = 16; - extradata.bLittleEndian = 1; - - avOut.data = packet.data; - avOut.len = packet.size; - avOut.pts = pts; - avOut.extradata = (unsigned char *) &extradata; - avOut.extralen = sizeof(extradata); - avOut.frameRate = 0; - avOut.timeScale = 0; - avOut.width = 0; - avOut.height = 0; - avOut.type = "audio"; - - if (!context->playback->BackWard - && context->output->audio->Write(context, - &avOut) < 0) { - ffmpeg_err - ("(raw pcm) writing data to audio device failed\n"); - } - } else if (audioTrack->inject_as_pcm == 1) { - AVCodecContext *c = - ((AVStream *) (audioTrack->stream))->codec; - - if (restart_audio_resampling) { - restart_audio_resampling = 0; - if (swr) { - swr_free(&swr); - swr = NULL; - } - if (decoded_frame) { - avcodec_free_frame(&decoded_frame); - decoded_frame = NULL; - } - context->output->Command(context, OUTPUT_CLEAR, NULL); - context->output->Command(context, OUTPUT_PLAY, NULL); - - AVCodec *codec = - avcodec_find_decoder(c->codec_id); - - if (!codec || avcodec_open2(c, codec, NULL)) - fprintf(stderr, "%s %d: avcodec_open2 failed\n", __func__, __LINE__); - } - - while (packet.size > 0) { - int got_frame = 0; - if (!decoded_frame) { - if (!(decoded_frame = avcodec_alloc_frame())) { - fprintf(stderr, "out of memory\n"); - exit(1); - } - } else - avcodec_get_frame_defaults(decoded_frame); - - int len = - avcodec_decode_audio4(c, decoded_frame, &got_frame, - &packet); - if (len < 0) { - restart_audio_resampling = 1; -// fprintf(stderr, "avcodec_decode_audio4: %d\n", len); - break; - } - - packet.data += len; - packet.size -= len; - - if (!got_frame) - continue; - - int e; - if (!swr) { - int rates[] = - { 48000, 96000, 192000, 44100, 88200, 176400, - 0 - }; - int *rate = rates; - int in_rate = c->sample_rate; - while (*rate - && ((*rate / in_rate) * in_rate != *rate) - && (in_rate / *rate) * *rate != in_rate) - rate++; - out_sample_rate = *rate ? *rate : 44100; - swr = swr_alloc(); - out_channels = c->channels; - if (c->channel_layout == 0) { - // FIXME -- need to guess, looks pretty much like a bug in the FFMPEG WMA decoder - c->channel_layout = AV_CH_LAYOUT_STEREO; - } - - out_channel_layout = c->channel_layout; - // player2 won't play mono - if (out_channel_layout == AV_CH_LAYOUT_MONO) { - out_channel_layout = AV_CH_LAYOUT_STEREO; - out_channels = 2; - } - - av_opt_set_int(swr, "in_channel_layout", - c->channel_layout, 0); - av_opt_set_int(swr, "out_channel_layout", - out_channel_layout, 0); - av_opt_set_int(swr, "in_sample_rate", - c->sample_rate, 0); - av_opt_set_int(swr, "out_sample_rate", - out_sample_rate, 0); - av_opt_set_int(swr, "in_sample_fmt", c->sample_fmt, - 0); - av_opt_set_int(swr, "out_sample_fmt", - AV_SAMPLE_FMT_S16, 0); - - e = swr_init(swr); - if (e < 0) { - fprintf(stderr, - "swr_init: %d (icl=%d ocl=%d isr=%d osr=%d isf=%d osf=%d\n", - -e, (int) c->channel_layout, - (int) out_channel_layout, - c->sample_rate, out_sample_rate, - c->sample_fmt, AV_SAMPLE_FMT_S16); - swr_free(&swr); - swr = NULL; - } - } - - uint8_t *output = NULL; - int in_samples = decoded_frame->nb_samples; - int out_samples = - av_rescale_rnd(swr_get_delay(swr, c->sample_rate) + - in_samples, out_sample_rate, - c->sample_rate, AV_ROUND_UP); - e = av_samples_alloc(&output, NULL, out_channels, - out_samples, AV_SAMPLE_FMT_S16, - 1); - if (e < 0) { - fprintf(stderr, "av_samples_alloc: %d\n", -e); - continue; - } - int64_t next_in_pts = - av_rescale(av_frame_get_best_effort_timestamp - (decoded_frame), - ((AVStream *) audioTrack->stream)-> - time_base.num * - (int64_t) out_sample_rate * - c->sample_rate, - ((AVStream *) audioTrack->stream)-> - time_base.den); - int64_t next_out_pts = - av_rescale(swr_next_pts(swr, next_in_pts), - ((AVStream *) audioTrack->stream)-> - time_base.den, - ((AVStream *) audioTrack->stream)-> - time_base.num * - (int64_t) out_sample_rate * - c->sample_rate); - currentAudioPts = audioTrack->pts = pts = - calcPts(audioTrack->stream, next_out_pts); - out_samples = - swr_convert(swr, &output, out_samples, - (const uint8_t **) - &decoded_frame->data[0], in_samples); + ffmpeg_printf(200, "AudioTrack index = %d\n", pid); + if (audioTrack->inject_raw_pcm == 1) { + ffmpeg_printf(200, "write audio raw pcm\n"); pcmPrivateData_t extradata; - - extradata.uSampleRate = out_sample_rate; - extradata.uNoOfChannels = - av_get_channel_layout_nb_channels - (out_channel_layout); + extradata.uNoOfChannels = ((AVStream *) audioTrack->stream)->codec->channels; + extradata.uSampleRate = ((AVStream *) audioTrack->stream)->codec->sample_rate; extradata.uBitsPerSample = 16; extradata.bLittleEndian = 1; - avOut.data = output; - avOut.len = out_samples * sizeof(short) * out_channels; - + avOut.data = packet.data; + avOut.len = packet.size; avOut.pts = pts; avOut.extradata = (unsigned char *) &extradata; avOut.extralen = sizeof(extradata); @@ -676,55 +481,180 @@ static void FFMPEGThread(Context_t * context) avOut.height = 0; avOut.type = "audio"; - if (!context->playback->BackWard - && context->output->audio->Write(context, - &avOut) < 0) - ffmpeg_err - ("writing data to audio device failed\n"); - av_freep(&output); - } - } else if (audioTrack->have_aacheader == 1) { - ffmpeg_printf(200, "write audio aac\n"); + if (context->output->audio->Write(context, &avOut) < 0) + ffmpeg_err("(raw pcm) writing data to audio device failed\n"); + } else if (audioTrack->inject_as_pcm == 1) { + AVCodecContext *c = ((AVStream *) (audioTrack->stream))->codec; - avOut.data = packet.data; - avOut.len = packet.size; - avOut.pts = pts; - avOut.extradata = audioTrack->aacbuf; - avOut.extralen = audioTrack->aacbuflen; - avOut.frameRate = 0; - avOut.timeScale = 0; - avOut.width = 0; - avOut.height = 0; - avOut.type = "audio"; + if (restart_audio_resampling) { + restart_audio_resampling = 0; + if (swr) { + swr_free(&swr); + swr = NULL; + } + if (decoded_frame) { + avcodec_free_frame(&decoded_frame); + decoded_frame = NULL; + } + context->output->Command(context, OUTPUT_CLEAR, NULL); + context->output->Command(context, OUTPUT_PLAY, NULL); - if (!context->playback->BackWard - && context->output->audio->Write(context, - &avOut) < 0) { - ffmpeg_err - ("(aac) writing data to audio device failed\n"); - } - } else { - avOut.data = packet.data; - avOut.len = packet.size; - avOut.pts = pts; - avOut.extradata = NULL; - avOut.extralen = 0; - avOut.frameRate = 0; - avOut.timeScale = 0; - avOut.width = 0; - avOut.height = 0; - avOut.type = "audio"; + AVCodec *codec = avcodec_find_decoder(c->codec_id); - if (!context->playback->BackWard - && context->output->audio->Write(context, - &avOut) < 0) { - ffmpeg_err("writing data to audio device failed\n"); + if (!codec || avcodec_open2(c, codec, NULL)) + fprintf(stderr, "%s %d: avcodec_open2 failed\n", __func__, __LINE__); + } + + while (packet.size > 0) { + int got_frame = 0; + if (!decoded_frame) { + if (!(decoded_frame = avcodec_alloc_frame())) { + fprintf(stderr, "out of memory\n"); + exit(1); + } + } else + avcodec_get_frame_defaults(decoded_frame); + + int len = avcodec_decode_audio4(c, decoded_frame, + &got_frame, + &packet); + if (len < 0) { + restart_audio_resampling = 1; +// fprintf(stderr, "avcodec_decode_audio4: %d\n", len); + break; + } + + packet.data += len; + packet.size -= len; + + if (!got_frame) + continue; + + int e; + if (!swr) { + int rates[] = { 48000, 96000, 192000, 44100, 88200, + 176400, + 0 + }; + int *rate = rates; + int in_rate = c->sample_rate; + while (*rate && ((*rate / in_rate) * in_rate != *rate) + && (in_rate / *rate) * *rate != in_rate) + rate++; + out_sample_rate = *rate ? *rate : 44100; + swr = swr_alloc(); + out_channels = c->channels; + if (c->channel_layout == 0) { + // FIXME -- need to guess, looks pretty much like a bug in the FFMPEG WMA decoder + c->channel_layout = AV_CH_LAYOUT_STEREO; + } + + out_channel_layout = c->channel_layout; + // player2 won't play mono + if (out_channel_layout == AV_CH_LAYOUT_MONO) { + out_channel_layout = AV_CH_LAYOUT_STEREO; + out_channels = 2; + } + + av_opt_set_int(swr, "in_channel_layout", c->channel_layout, 0); + av_opt_set_int(swr, "out_channel_layout", out_channel_layout, 0); + av_opt_set_int(swr, "in_sample_rate", c->sample_rate, 0); + av_opt_set_int(swr, "out_sample_rate", out_sample_rate, 0); + av_opt_set_int(swr, "in_sample_fmt", c->sample_fmt, 0); + av_opt_set_int(swr, "out_sample_fmt", AV_SAMPLE_FMT_S16, 0); + + e = swr_init(swr); + if (e < 0) { + fprintf(stderr, + "swr_init: %d (icl=%d ocl=%d isr=%d osr=%d isf=%d osf=%d\n", + -e, (int) c->channel_layout, + (int) out_channel_layout, c->sample_rate, out_sample_rate, c->sample_fmt, AV_SAMPLE_FMT_S16); + swr_free(&swr); + swr = NULL; + } + } + + uint8_t *output = NULL; + int in_samples = decoded_frame->nb_samples; + int out_samples = av_rescale_rnd(swr_get_delay(swr, + c->sample_rate) + in_samples, + out_sample_rate, + c->sample_rate, AV_ROUND_UP); + e = av_samples_alloc(&output, NULL, out_channels, out_samples, AV_SAMPLE_FMT_S16, 1); + if (e < 0) { + fprintf(stderr, "av_samples_alloc: %d\n", -e); + continue; + } + int64_t next_in_pts = av_rescale(av_frame_get_best_effort_timestamp(decoded_frame), + ((AVStream *) audioTrack->stream)->time_base.num * (int64_t) out_sample_rate * c->sample_rate, + ((AVStream *) audioTrack->stream)->time_base.den); + int64_t next_out_pts = av_rescale(swr_next_pts(swr, next_in_pts), + ((AVStream *) audioTrack->stream)->time_base.den, + ((AVStream *) audioTrack->stream)->time_base.num * (int64_t) out_sample_rate * c->sample_rate); + currentAudioPts = audioTrack->pts = pts = calcPts(audioTrack->stream, next_out_pts); + out_samples = swr_convert(swr, &output, out_samples, (const uint8_t **) + &decoded_frame->data[0], in_samples); + + pcmPrivateData_t extradata; + + extradata.uSampleRate = out_sample_rate; + extradata.uNoOfChannels = av_get_channel_layout_nb_channels(out_channel_layout); + extradata.uBitsPerSample = 16; + extradata.bLittleEndian = 1; + + avOut.data = output; + avOut.len = out_samples * sizeof(short) * out_channels; + + avOut.pts = pts; + avOut.extradata = (unsigned char *) &extradata; + avOut.extralen = sizeof(extradata); + avOut.frameRate = 0; + avOut.timeScale = 0; + avOut.width = 0; + avOut.height = 0; + avOut.type = "audio"; + + if (context->output->audio->Write(context, &avOut) < 0) + ffmpeg_err("writing data to audio device failed\n"); + av_freep(&output); + } +#if 0 + } else if (audioTrack->have_aacheader == 1) { + ffmpeg_printf(200, "write audio aac\n"); + + avOut.data = packet.data; + avOut.len = packet.size; + avOut.pts = pts; + avOut.extradata = audioTrack->aacbuf; + avOut.extralen = audioTrack->aacbuflen; + avOut.frameRate = 0; + avOut.timeScale = 0; + avOut.width = 0; + avOut.height = 0; + avOut.type = "audio"; + + if (context->output->audio->Write(context, &avOut) < 0) + ffmpeg_err("(aac) writing data to audio device failed\n"); +#endif + } else { + avOut.data = packet.data; + avOut.len = packet.size; + avOut.pts = pts; + avOut.extradata = NULL; + avOut.extralen = 0; + avOut.frameRate = 0; + avOut.timeScale = 0; + avOut.width = 0; + avOut.height = 0; + avOut.type = "audio"; + + if (context->output->audio->Write(context, &avOut) < 0) + ffmpeg_err("writing data to audio device failed\n"); } } } else if (subtitleTrack && (subtitleTrack->Id == pid)) { float duration = 3.0; - ffmpeg_printf(100, "subtitleTrack->stream %p \n", - subtitleTrack->stream); + ffmpeg_printf(100, "subtitleTrack->stream %p \n", subtitleTrack->stream); pts = calcPts(subtitleTrack->stream, packet.pts); @@ -733,16 +663,13 @@ static void FFMPEGThread(Context_t * context) /*Hellmaster1024: in mkv the duration for ID_TEXT is stored in convergence_duration */ ffmpeg_printf(20, "Packet duration %d\n", packet.duration); - ffmpeg_printf(20, "Packet convergence_duration %lld\n", - packet.convergence_duration); + ffmpeg_printf(20, "Packet convergence_duration %lld\n", packet.convergence_duration); if (packet.duration != 0) // FIXME: packet.duration is 32 bit, AV_NOPTS_VALUE is 64 bit --martii duration = ((float) packet.duration) / 1000.0; - else if (packet.convergence_duration != 0 - && packet.convergence_duration != AV_NOPTS_VALUE) + else if (packet.convergence_duration != 0 && packet.convergence_duration != AV_NOPTS_VALUE) duration = ((float) packet.convergence_duration) / 1000.0; - else if (((AVStream *) subtitleTrack->stream)->codec-> - codec_id == AV_CODEC_ID_SSA) { + else if (((AVStream *) subtitleTrack->stream)->codec->codec_id == AV_CODEC_ID_SSA) { /*Hellmaster1024 if the duration is not stored in packet.duration or packet.convergence_duration we need to calculate it any other way, for SSA it is stored in the Text line */ @@ -761,18 +688,14 @@ static void FFMPEGThread(Context_t * context) AVSubtitle sub; int got_sub_ptr; - if (avcodec_decode_subtitle2 - (((AVStream *) subtitleTrack->stream)->codec, &sub, - &got_sub_ptr, &packet) < 0) { + if (avcodec_decode_subtitle2(((AVStream *) subtitleTrack->stream)->codec, &sub, &got_sub_ptr, &packet) < 0) { ffmpeg_err("error decoding subtitle\n"); } else { unsigned int i; ffmpeg_printf(0, "format %d\n", sub.format); - ffmpeg_printf(0, "start_display_time %d\n", - sub.start_display_time); - ffmpeg_printf(0, "end_display_time %d\n", - sub.end_display_time); + ffmpeg_printf(0, "start_display_time %d\n", sub.start_display_time); + ffmpeg_printf(0, "end_display_time %d\n", sub.end_display_time); ffmpeg_printf(0, "num_rects %d\n", sub.num_rects); ffmpeg_printf(0, "pts %lld\n", sub.pts); @@ -782,25 +705,19 @@ static void FFMPEGThread(Context_t * context) ffmpeg_printf(0, "y %d\n", sub.rects[i]->y); ffmpeg_printf(0, "w %d\n", sub.rects[i]->w); ffmpeg_printf(0, "h %d\n", sub.rects[i]->h); - ffmpeg_printf(0, "nb_colors %d\n", - sub.rects[i]->nb_colors); - ffmpeg_printf(0, "type %d\n", - sub.rects[i]->type); - ffmpeg_printf(0, "text %s\n", - sub.rects[i]->text); - ffmpeg_printf(0, "ass %s\n", - sub.rects[i]->ass); + ffmpeg_printf(0, "nb_colors %d\n", sub.rects[i]->nb_colors); + ffmpeg_printf(0, "type %d\n", sub.rects[i]->type); + ffmpeg_printf(0, "text %s\n", sub.rects[i]->text); + ffmpeg_printf(0, "ass %s\n", sub.rects[i]->ass); // pict ->AVPicture } } - if (((AVStream *) subtitleTrack->stream)->codec-> - codec_id == AV_CODEC_ID_SSA) { + if (((AVStream *) subtitleTrack->stream)->codec->codec_id == AV_CODEC_ID_SSA) { SubtitleData_t data; - ffmpeg_printf(10, "videoPts %lld\n", - currentVideoPts); + ffmpeg_printf(10, "videoPts %lld\n", currentVideoPts); data.data = packet.data; data.len = packet.size; @@ -809,40 +726,30 @@ static void FFMPEGThread(Context_t * context) data.pts = pts; data.duration = duration; - context->container->assContainer->Command(context, - CONTAINER_DATA, - &data); + context->container->assContainer->Command(context, CONTAINER_DATA, &data); } else { /* hopefully native text ;) */ - unsigned char *line = - text_to_ass((char *) packet.data, pts / 90, - duration); - ffmpeg_printf(50, "text line is %s\n", - (char *) packet.data); + unsigned char *line = text_to_ass((char *) packet.data, pts / 90, + duration); + ffmpeg_printf(50, "text line is %s\n", (char *) packet.data); ffmpeg_printf(50, "Sub line is %s\n", line); - ffmpeg_printf(20, "videoPts %lld %f\n", - currentVideoPts, - currentVideoPts / 90000.0); + ffmpeg_printf(20, "videoPts %lld %f\n", currentVideoPts, currentVideoPts / 90000.0); SubtitleData_t data; data.data = line; data.len = strlen((char *) line); - data.extradata = - (unsigned char *) DEFAULT_ASS_HEAD; + data.extradata = (unsigned char *) DEFAULT_ASS_HEAD; data.extralen = strlen(DEFAULT_ASS_HEAD); data.pts = pts; data.duration = duration; - context->container->assContainer->Command(context, - CONTAINER_DATA, - &data); + context->container->assContainer->Command(context, CONTAINER_DATA, &data); free(line); } } } /* duration */ } else if (dvbsubtitleTrack && (dvbsubtitleTrack->Id == pid)) { - dvbsubtitleTrack->pts = pts = - calcPts(dvbsubtitleTrack->stream, packet.pts); + dvbsubtitleTrack->pts = pts = calcPts(dvbsubtitleTrack->stream, packet.pts); ffmpeg_printf(200, "DvbSubTitle index = %d\n", pid); @@ -861,8 +768,7 @@ static void FFMPEGThread(Context_t * context) //ffmpeg_err("writing data to dvbsubtitle fifo failed\n"); } } else if (teletextTrack && (teletextTrack->Id == pid)) { - teletextTrack->pts = pts = - calcPts(teletextTrack->stream, packet.pts); + teletextTrack->pts = pts = calcPts(teletextTrack->stream, packet.pts); ffmpeg_printf(200, "TeleText index = %d\n", pid); @@ -885,8 +791,7 @@ static void FFMPEGThread(Context_t * context) av_free_packet(&packet); } /* while */ - if (context && context->playback && context->output - && context->playback->abortRequested) + if (context && context->playback && context->output && context->playback->abortRequested) context->output->Command(context, OUTPUT_CLEAR, NULL); if (swr) @@ -914,7 +819,7 @@ static int interrupt_cb(void *ctx) static void log_callback(void *ptr __attribute__ ((unused)), int lvl __attribute__ ((unused)), const char *format, va_list ap) { - vfprintf(stderr, format, ap); + vfprintf(stderr, format, ap); } int container_ffmpeg_init(Context_t * context, char *filename) @@ -995,8 +900,7 @@ int container_ffmpeg_init(Context_t * context, char *filename) return res; } -int container_ffmpeg_update_tracks(Context_t * context, char *filename, - int initial) +int container_ffmpeg_update_tracks(Context_t * context, char *filename, int initial) { if (terminating) return cERR_CONTAINER_FFMPEG_NO_ERROR; @@ -1006,33 +910,24 @@ int container_ffmpeg_update_tracks(Context_t * context, char *filename, Track_t *dvbsubtitleTrack = NULL; Track_t *teletextTrack = NULL; - context->manager->audio->Command(context, MANAGER_GET_TRACK, - &audioTrack); + context->manager->audio->Command(context, MANAGER_GET_TRACK, &audioTrack); if (initial) - context->manager->subtitle->Command(context, MANAGER_GET_TRACK, - &subtitleTrack); - context->manager->dvbsubtitle->Command(context, MANAGER_GET_TRACK, - &dvbsubtitleTrack); - context->manager->teletext->Command(context, MANAGER_GET_TRACK, - &teletextTrack); + context->manager->subtitle->Command(context, MANAGER_GET_TRACK, &subtitleTrack); + context->manager->dvbsubtitle->Command(context, MANAGER_GET_TRACK, &dvbsubtitleTrack); + context->manager->teletext->Command(context, MANAGER_GET_TRACK, &teletextTrack); if (context->manager->video) - context->manager->video->Command(context, MANAGER_INIT_UPDATE, - NULL); + context->manager->video->Command(context, MANAGER_INIT_UPDATE, NULL); if (context->manager->audio) - context->manager->audio->Command(context, MANAGER_INIT_UPDATE, - NULL); + context->manager->audio->Command(context, MANAGER_INIT_UPDATE, NULL); #if 0 if (context->manager->subtitle) - context->manager->subtitle->Command(context, MANAGER_INIT_UPDATE, - NULL); + context->manager->subtitle->Command(context, MANAGER_INIT_UPDATE, NULL); #endif if (context->manager->dvbsubtitle) - context->manager->dvbsubtitle->Command(context, - MANAGER_INIT_UPDATE, NULL); + context->manager->dvbsubtitle->Command(context, MANAGER_INIT_UPDATE, NULL); if (context->manager->teletext) - context->manager->teletext->Command(context, MANAGER_INIT_UPDATE, - NULL); + context->manager->teletext->Command(context, MANAGER_INIT_UPDATE, NULL); ffmpeg_printf(20, "dump format\n"); av_dump_format(avContext, 0, filename, 0); @@ -1049,8 +944,7 @@ int container_ffmpeg_update_tracks(Context_t * context, char *filename, char *encoding = Codec2Encoding(stream->codec, &version); if (encoding != NULL) - ffmpeg_printf(1, "%d. encoding = %s - version %d\n", n, - encoding, version); + ffmpeg_printf(1, "%d. encoding = %s - version %d\n", n, encoding, version); if (!stream->id) stream->id = n; @@ -1062,8 +956,7 @@ int container_ffmpeg_update_tracks(Context_t * context, char *filename, switch (stream->codec->codec_type) { case AVMEDIA_TYPE_VIDEO: - ffmpeg_printf(10, "CODEC_TYPE_VIDEO %d\n", - stream->codec->codec_type); + ffmpeg_printf(10, "CODEC_TYPE_VIDEO %d\n", stream->codec->codec_type); if (encoding != NULL) { track.type = eTypeES; @@ -1077,8 +970,10 @@ int container_ffmpeg_update_tracks(Context_t * context, char *filename, track.frame_rate = stream->r_frame_rate.num; +#if 0 track.aacbuf = 0; track.have_aacheader = -1; +#endif double frame_rate = av_q2d(stream->r_frame_rate); /* rational to double */ @@ -1093,19 +988,13 @@ int container_ffmpeg_update_tracks(Context_t * context, char *filename, else track.TimeScale = 1000; - ffmpeg_printf(10, "bit_rate = %d\n", - stream->codec->bit_rate); + ffmpeg_printf(10, "bit_rate = %d\n", stream->codec->bit_rate); ffmpeg_printf(10, "flags = %d\n", stream->codec->flags); - ffmpeg_printf(10, "frame_bits = %d\n", - stream->codec->frame_bits); - ffmpeg_printf(10, "time_base.den %d\n", - stream->time_base.den); - ffmpeg_printf(10, "time_base.num %d\n", - stream->time_base.num); - ffmpeg_printf(10, "frame_rate %d\n", - stream->r_frame_rate.num); - ffmpeg_printf(10, "TimeScale %d\n", - stream->r_frame_rate.den); + ffmpeg_printf(10, "frame_bits = %d\n", stream->codec->frame_bits); + ffmpeg_printf(10, "time_base.den %d\n", stream->time_base.den); + ffmpeg_printf(10, "time_base.num %d\n", stream->time_base.num); + ffmpeg_printf(10, "frame_rate %d\n", stream->r_frame_rate.num); + ffmpeg_printf(10, "TimeScale %d\n", stream->r_frame_rate.den); ffmpeg_printf(10, "frame_rate %d\n", track.frame_rate); ffmpeg_printf(10, "TimeScale %d\n", track.TimeScale); @@ -1116,30 +1005,24 @@ int container_ffmpeg_update_tracks(Context_t * context, char *filename, track.Id = stream->id; if (stream->duration == AV_NOPTS_VALUE) { - ffmpeg_printf(10, - "Stream has no duration so we take the duration from context\n"); + ffmpeg_printf(10, "Stream has no duration so we take the duration from context\n"); track.duration = (double) avContext->duration / 1000.0; } else { - track.duration = - (double) stream->duration * - av_q2d(stream->time_base) * 1000.0; + track.duration = (double) stream->duration * av_q2d(stream->time_base) * 1000.0; } if (context->manager->video) - if (context->manager->video-> - Command(context, MANAGER_ADD, &track) < 0) { + if (context->manager->video->Command(context, MANAGER_ADD, &track) < 0) { /* konfetti: fixme: is this a reason to return with error? */ ffmpeg_err("failed to add track %d\n", n); } } else { - ffmpeg_err("codec type video but codec unknown %d\n", - stream->codec->codec_id); + ffmpeg_err("codec type video but codec unknown %d\n", stream->codec->codec_id); } break; case AVMEDIA_TYPE_AUDIO: - ffmpeg_printf(10, "CODEC_TYPE_AUDIO %d\n", - stream->codec->codec_type); + ffmpeg_printf(10, "CODEC_TYPE_AUDIO %d\n", stream->codec->codec_type); if (encoding != NULL) { AVDictionaryEntry *lang; @@ -1154,34 +1037,28 @@ int container_ffmpeg_update_tracks(Context_t * context, char *filename, track.Encoding = encoding; track.stream = stream; track.Id = stream->id; - track.duration = - (double) stream->duration * av_q2d(stream->time_base) * - 1000.0; + track.duration = (double) stream->duration * av_q2d(stream->time_base) * 1000.0; +#if 0 track.aacbuf = 0; track.have_aacheader = -1; +#endif if (stream->duration == AV_NOPTS_VALUE) { - ffmpeg_printf(10, - "Stream has no duration so we take the duration from context\n"); + ffmpeg_printf(10, "Stream has no duration so we take the duration from context\n"); track.duration = (double) avContext->duration / 1000.0; } else { - track.duration = - (double) stream->duration * - av_q2d(stream->time_base) * 1000.0; + track.duration = (double) stream->duration * av_q2d(stream->time_base) * 1000.0; } if (!strncmp(encoding, "A_IPCM", 6)) { track.inject_as_pcm = 1; - ffmpeg_printf(10, " Handle inject_as_pcm = %d\n", - track.inject_as_pcm); + ffmpeg_printf(10, " Handle inject_as_pcm = %d\n", track.inject_as_pcm); } #if 0 else if (stream->codec->codec_id == AV_CODEC_ID_AAC) { ffmpeg_printf(10, "Create AAC ExtraData\n"); - ffmpeg_printf(10, "stream->codec->extradata_size %d\n", - stream->codec->extradata_size); - Hexdump(stream->codec->extradata, - stream->codec->extradata_size); + ffmpeg_printf(10, "stream->codec->extradata_size %d\n", stream->codec->extradata_size); + Hexdump(stream->codec->extradata, stream->codec->extradata_size); /* extradata 13 10 56 e5 9d 48 00 (anderen cops) @@ -1199,22 +1076,18 @@ int container_ffmpeg_update_tracks(Context_t * context, char *filename, */ unsigned int object_type = 2; // LC - unsigned int sample_index = - aac_get_sample_rate_index(stream->codec-> - sample_rate); + unsigned int sample_index = aac_get_sample_rate_index(stream->codec->sample_rate); unsigned int chan_config = stream->codec->channels; if (stream->codec->extradata_size >= 2) { object_type = stream->codec->extradata[0] >> 3; - sample_index = - ((stream->codec->extradata[0] & 0x7) << 1) + sample_index = ((stream->codec->extradata[0] & 0x7) << 1) + (stream->codec->extradata[1] >> 7); chan_config = (stream->codec->extradata[1] >> 3) && 0xf; } ffmpeg_printf(10, "aac object_type %d\n", object_type); - ffmpeg_printf(10, "aac sample_index %d\n", - sample_index); + ffmpeg_printf(10, "aac sample_index %d\n", sample_index); ffmpeg_printf(10, "aac chan_config %d\n", chan_config); object_type -= 1; // Cause of ADTS @@ -1223,9 +1096,7 @@ int container_ffmpeg_update_tracks(Context_t * context, char *filename, track.aacbuf = malloc(8); track.aacbuf[0] = 0xFF; track.aacbuf[1] = 0xF1; - track.aacbuf[2] = - ((object_type & 0x03) << 6) | (sample_index << 2) | - ((chan_config >> 2) & 0x01); + track.aacbuf[2] = ((object_type & 0x03) << 6) | (sample_index << 2) | ((chan_config >> 2) & 0x01); track.aacbuf[3] = (chan_config & 0x03) << 6; track.aacbuf[4] = 0x00; track.aacbuf[5] = 0x1F; @@ -1241,8 +1112,7 @@ int container_ffmpeg_update_tracks(Context_t * context, char *filename, track.aacbuflen = 104 + stream->codec->extradata_size; track.aacbuf = malloc(track.aacbuflen); memset(track.aacbuf, 0, track.aacbuflen); - unsigned char ASF_Stream_Properties_Object[16] = - { 0x91, 0x07, 0xDC, 0xB7, 0xB7, 0xA9, 0xCF, 0x11, + unsigned char ASF_Stream_Properties_Object[16] = { 0x91, 0x07, 0xDC, 0xB7, 0xB7, 0xA9, 0xCF, 0x11, 0x8E, 0xE6, 0x00, 0xC0, 0x0C, 0x20, 0x53, 0x65 }; memcpy(track.aacbuf + 0, ASF_Stream_Properties_Object, 16); // ASF_Stream_Properties_Object @@ -1251,14 +1121,12 @@ int container_ffmpeg_update_tracks(Context_t * context, char *filename, unsigned int sizehi = 0; memcpy(track.aacbuf + 20, &sizehi, 4); // sizehi (not used) - unsigned char ASF_Audio_Media[16] = - { 0x40, 0x9E, 0x69, 0xF8, 0x4D, 0x5B, 0xCF, 0x11, + unsigned char ASF_Audio_Media[16] = { 0x40, 0x9E, 0x69, 0xF8, 0x4D, 0x5B, 0xCF, 0x11, 0xA8, 0xFD, 0x00, 0x80, 0x5F, 0x5C, 0x44, 0x2B }; memcpy(track.aacbuf + 24, ASF_Audio_Media, 16); //ASF_Audio_Media - unsigned char ASF_Audio_Spread[16] = - { 0x50, 0xCD, 0xC3, 0xBF, 0x8F, 0x61, 0xCF, 0x11, + unsigned char ASF_Audio_Spread[16] = { 0x50, 0xCD, 0xC3, 0xBF, 0x8F, 0x61, 0xCF, 0x11, 0x8B, 0xB2, 0x00, 0xAA, 0x00, 0xB4, 0xE2, 0x20 }; memcpy(track.aacbuf + 40, ASF_Audio_Spread, 16); //ASF_Audio_Spread @@ -1266,8 +1134,7 @@ int container_ffmpeg_update_tracks(Context_t * context, char *filename, memset(track.aacbuf + 56, 0, 4); // time_offset (not used) memset(track.aacbuf + 60, 0, 4); // time_offset_hi (not used) - unsigned int type_specific_data_length = - 18 + stream->codec->extradata_size; + unsigned int type_specific_data_length = 18 + stream->codec->extradata_size; memcpy(track.aacbuf + 64, &type_specific_data_length, 4); //type_specific_data_length unsigned int error_correction_data_length = 8; @@ -1300,41 +1167,28 @@ int container_ffmpeg_update_tracks(Context_t * context, char *filename, } memcpy(track.aacbuf + 78, &codec_id, 2); //codec_id - unsigned short number_of_channels = - stream->codec->channels; + unsigned short number_of_channels = stream->codec->channels; memcpy(track.aacbuf + 80, &number_of_channels, 2); //number_of_channels - unsigned int samples_per_second = - stream->codec->sample_rate; - ffmpeg_printf(1, "samples_per_second = %d\n", - samples_per_second); + unsigned int samples_per_second = stream->codec->sample_rate; + ffmpeg_printf(1, "samples_per_second = %d\n", samples_per_second); memcpy(track.aacbuf + 82, &samples_per_second, 4); //samples_per_second - unsigned int average_number_of_bytes_per_second = - stream->codec->bit_rate / 8; - ffmpeg_printf(1, - "average_number_of_bytes_per_second = %d\n", - average_number_of_bytes_per_second); + unsigned int average_number_of_bytes_per_second = stream->codec->bit_rate / 8; + ffmpeg_printf(1, "average_number_of_bytes_per_second = %d\n", average_number_of_bytes_per_second); memcpy(track.aacbuf + 86, &average_number_of_bytes_per_second, 4); //average_number_of_bytes_per_second - unsigned short block_alignment = - stream->codec->block_align; - ffmpeg_printf(1, "block_alignment = %d\n", - block_alignment); + unsigned short block_alignment = stream->codec->block_align; + ffmpeg_printf(1, "block_alignment = %d\n", block_alignment); memcpy(track.aacbuf + 90, &block_alignment, 2); //block_alignment - unsigned short bits_per_sample = - stream->codec->sample_fmt >= - 0 ? (stream->codec->sample_fmt + 1) * 8 : 8; - ffmpeg_printf(1, "bits_per_sample = %d (%d)\n", - bits_per_sample, - stream->codec->sample_fmt); + unsigned short bits_per_sample = stream->codec->sample_fmt >= 0 ? (stream->codec->sample_fmt + 1) * 8 : 8; + ffmpeg_printf(1, "bits_per_sample = %d (%d)\n", bits_per_sample, stream->codec->sample_fmt); memcpy(track.aacbuf + 92, &bits_per_sample, 2); //bits_per_sample memcpy(track.aacbuf + 94, &stream->codec->extradata_size, 2); //bits_per_sample - memcpy(track.aacbuf + 96, stream->codec->extradata, - stream->codec->extradata_size); + memcpy(track.aacbuf + 96, stream->codec->extradata, stream->codec->extradata_size); ffmpeg_printf(1, "aacbuf:\n"); Hexdump(track.aacbuf, track.aacbuflen); @@ -1347,24 +1201,21 @@ int container_ffmpeg_update_tracks(Context_t * context, char *filename, #endif if (context->manager->audio) { - if (context->manager->audio-> - Command(context, MANAGER_ADD, &track) < 0) { + if (context->manager->audio->Command(context, MANAGER_ADD, &track) < 0) { /* konfetti: fixme: is this a reason to return with error? */ ffmpeg_err("failed to add track %d\n", n); } } } else { - ffmpeg_err("codec type audio but codec unknown %d\n", - stream->codec->codec_id); + ffmpeg_err("codec type audio but codec unknown %d\n", stream->codec->codec_id); } break; case AVMEDIA_TYPE_SUBTITLE: { AVDictionaryEntry *lang; - ffmpeg_printf(10, "CODEC_TYPE_SUBTITLE %d\n", - stream->codec->codec_type); + ffmpeg_printf(10, "CODEC_TYPE_SUBTITLE %d\n", stream->codec->codec_type); lang = av_dict_get(stream->metadata, "language", NULL, 0); @@ -1375,12 +1226,12 @@ int container_ffmpeg_update_tracks(Context_t * context, char *filename, track.Encoding = encoding; track.stream = stream; track.Id = stream->id; - track.duration = - (double) stream->duration * av_q2d(stream->time_base) * - 1000.0; + track.duration = (double) stream->duration * av_q2d(stream->time_base) * 1000.0; +#if 0 track.aacbuf = 0; track.have_aacheader = -1; +#endif track.width = -1; /* will be filled online from videotrack */ track.height = -1; /* will be filled online from videotrack */ @@ -1388,28 +1239,21 @@ int container_ffmpeg_update_tracks(Context_t * context, char *filename, track.extraData = stream->codec->extradata; track.extraSize = stream->codec->extradata_size; - ffmpeg_printf(1, "subtitle codec %d\n", - stream->codec->codec_id); - ffmpeg_printf(1, "subtitle width %d\n", - stream->codec->width); - ffmpeg_printf(1, "subtitle height %d\n", - stream->codec->height); + ffmpeg_printf(1, "subtitle codec %d\n", stream->codec->codec_id); + ffmpeg_printf(1, "subtitle width %d\n", stream->codec->width); + ffmpeg_printf(1, "subtitle height %d\n", stream->codec->height); ffmpeg_printf(1, "subtitle stream %p\n", stream); if (stream->duration == AV_NOPTS_VALUE) { - ffmpeg_printf(10, - "Stream has no duration so we take the duration from context\n"); + ffmpeg_printf(10, "Stream has no duration so we take the duration from context\n"); track.duration = (double) avContext->duration / 1000.0; } else { - track.duration = - (double) stream->duration * - av_q2d(stream->time_base) * 1000.0; + track.duration = (double) stream->duration * av_q2d(stream->time_base) * 1000.0; } ffmpeg_printf(10, "FOUND SUBTITLE %s\n", track.Name); - if (stream->codec->codec_id == AV_CODEC_ID_DVB_TELETEXT - && context->manager->teletext) { + if (stream->codec->codec_id == AV_CODEC_ID_DVB_TELETEXT && context->manager->teletext) { ffmpeg_printf(10, "dvb_teletext\n"); int i = 0; AVDictionaryEntry *t = NULL; @@ -1419,47 +1263,28 @@ int container_ffmpeg_update_tracks(Context_t * context, char *filename, t = av_dict_get(stream->metadata, tmp, NULL, 0); if (t) { track.Name = t->value; - if (context->manager->teletext-> - Command(context, MANAGER_ADD, &track) < 0) - ffmpeg_err - ("failed to add teletext track %d\n", - n); + if (context->manager->teletext->Command(context, MANAGER_ADD, &track) < 0) + ffmpeg_err("failed to add teletext track %d\n", n); } i++; } while (t); - } else if (stream->codec->codec_id == - AV_CODEC_ID_DVB_SUBTITLE - && context->manager->dvbsubtitle) { + } else if (stream->codec->codec_id == AV_CODEC_ID_DVB_SUBTITLE && context->manager->dvbsubtitle) { ffmpeg_printf(10, "dvb_subtitle\n"); - lang = - av_dict_get(stream->metadata, "language", NULL, 0); - if (context->manager->dvbsubtitle-> - Command(context, MANAGER_ADD, &track) < 0) { - ffmpeg_err("failed to add dvbsubtitle track %d\n", - n); + lang = av_dict_get(stream->metadata, "language", NULL, 0); + if (context->manager->dvbsubtitle->Command(context, MANAGER_ADD, &track) < 0) { + ffmpeg_err("failed to add dvbsubtitle track %d\n", n); } } else if (initial && context->manager->subtitle) { if (!stream->codec->codec) { - stream->codec->codec = - avcodec_find_decoder(stream->codec->codec_id); + stream->codec->codec = avcodec_find_decoder(stream->codec->codec_id); if (!stream->codec->codec) - ffmpeg_err - ("avcodec_find_decoder failed for subtitle track %d\n", - n); - else if (avcodec_open2 - (stream->codec, stream->codec->codec, - NULL)) { - ffmpeg_err - ("avcodec_open2 failed for subtitle track %d\n", - n); + ffmpeg_err("avcodec_find_decoder failed for subtitle track %d\n", n); + else if (avcodec_open2(stream->codec, stream->codec->codec, NULL)) { + ffmpeg_err("avcodec_open2 failed for subtitle track %d\n", n); stream->codec->codec = NULL; } } - if (stream->codec->codec - && context->manager->subtitle->Command(context, - MANAGER_ADD, - &track) < - 0) { + if (stream->codec->codec && context->manager->subtitle->Command(context, MANAGER_ADD, &track) < 0) { /* konfetti: fixme: is this a reason to return with error? */ ffmpeg_err("failed to add subtitle track %d\n", n); } @@ -1472,8 +1297,7 @@ int container_ffmpeg_update_tracks(Context_t * context, char *filename, case AVMEDIA_TYPE_ATTACHMENT: case AVMEDIA_TYPE_NB: default: - ffmpeg_err("not handled or unknown codec_type %d\n", - stream->codec->codec_type); + ffmpeg_err("not handled or unknown codec_type %d\n", stream->codec->codec_type); break; } @@ -1500,11 +1324,8 @@ static int container_ffmpeg_play(Context_t * context) pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - if ((error = - pthread_create(&PlayThread, &attr, (void *) &FFMPEGThread, - context)) != 0) { - ffmpeg_printf(10, "Error creating thread, error:%d:%s\n", - error, strerror(error)); + if ((error = pthread_create(&PlayThread, &attr, (void *) &FFMPEGThread, context)) != 0) { + ffmpeg_printf(10, "Error creating thread, error:%d:%s\n", error, strerror(error)); ret = cERR_CONTAINER_FFMPEG_ERR; } else { ffmpeg_printf(10, "Created thread\n"); @@ -1547,9 +1368,7 @@ static int container_ffmpeg_stop(Context_t * context) return ret; } -static int container_ffmpeg_seek(Context_t * context - __attribute__ ((unused)), float sec, - int absolute) +static int container_ffmpeg_seek(Context_t * context __attribute__ ((unused)), float sec, int absolute) { if (absolute) seek_sec_abs = sec, seek_sec_rel = 0.0; @@ -1571,12 +1390,9 @@ static int container_ffmpeg_get_length(Context_t * context, double *length) return cERR_CONTAINER_FFMPEG_ERR; } - context->manager->video->Command(context, MANAGER_GET_TRACK, - &videoTrack); - context->manager->audio->Command(context, MANAGER_GET_TRACK, - &audioTrack); - context->manager->subtitle->Command(context, MANAGER_GET_TRACK, - &subtitleTrack); + context->manager->video->Command(context, MANAGER_GET_TRACK, &videoTrack); + context->manager->audio->Command(context, MANAGER_GET_TRACK, &audioTrack); + context->manager->subtitle->Command(context, MANAGER_GET_TRACK, &subtitleTrack); if (videoTrack != NULL) current = videoTrack; @@ -1613,27 +1429,18 @@ static int container_ffmpeg_switch_audio(Context_t * context, int *arg) return cERR_CONTAINER_FFMPEG_NO_ERROR; } -static int container_ffmpeg_switch_subtitle(Context_t * context - __attribute__ ((unused)), - int *arg - __attribute__ ((unused))) +static int container_ffmpeg_switch_subtitle(Context_t * context __attribute__ ((unused)), int *arg __attribute__ ((unused))) { /* Hellmaster1024: nothing to do here! */ return cERR_CONTAINER_FFMPEG_NO_ERROR; } -static int container_ffmpeg_switch_dvbsubtitle(Context_t * context - __attribute__ ((unused)), - int *arg - __attribute__ ((unused))) +static int container_ffmpeg_switch_dvbsubtitle(Context_t * context __attribute__ ((unused)), int *arg __attribute__ ((unused))) { return cERR_CONTAINER_FFMPEG_NO_ERROR; } -static int container_ffmpeg_switch_teletext(Context_t * context - __attribute__ ((unused)), - int *arg - __attribute__ ((unused))) +static int container_ffmpeg_switch_teletext(Context_t * context __attribute__ ((unused)), int *arg __attribute__ ((unused))) { return cERR_CONTAINER_FFMPEG_NO_ERROR; } @@ -1646,8 +1453,7 @@ static int container_ffmpeg_switch_teletext(Context_t * context * I do not free the string here because this is the wrong way. The mechanism * should be changed, or e2 should pass it in a different way... */ -static int container_ffmpeg_get_info(Context_t * context, - char **infoString) +static int container_ffmpeg_get_info(Context_t * context, char **infoString) { Track_t *videoTrack = NULL; Track_t *audioTrack = NULL; @@ -1663,10 +1469,8 @@ static int container_ffmpeg_get_info(Context_t * context, ffmpeg_printf(20, "%s\n", *infoString); - context->manager->video->Command(context, MANAGER_GET_TRACK, - &videoTrack); - context->manager->audio->Command(context, MANAGER_GET_TRACK, - &audioTrack); + context->manager->video->Command(context, MANAGER_GET_TRACK, &videoTrack); + context->manager->audio->Command(context, MANAGER_GET_TRACK, &audioTrack); if ((meta = searchMeta(avContext->metadata, *infoString)) == NULL) { if (audioTrack != NULL) { @@ -1685,8 +1489,7 @@ static int container_ffmpeg_get_info(Context_t * context, if (meta != NULL) { *infoString = strdup(meta); } else { - ffmpeg_printf(1, "no metadata found for \"%s\"\n", - *infoString); + ffmpeg_printf(1, "no metadata found for \"%s\"\n", *infoString); *infoString = strdup("not found"); } } else { @@ -1724,15 +1527,11 @@ static int Command(void *_context, ContainerCmd_t command, void *argument) break; } case CONTAINER_SEEK:{ - ret = - container_ffmpeg_seek(context, - (float) *((float *) argument), 0); + ret = container_ffmpeg_seek(context, (float) *((float *) argument), 0); break; } case CONTAINER_SEEK_ABS:{ - ret = - container_ffmpeg_seek(context, - (float) *((float *) argument), -1); + ret = container_ffmpeg_seek(context, (float) *((float *) argument), -1); break; } case CONTAINER_LENGTH:{ @@ -1747,9 +1546,7 @@ static int Command(void *_context, ContainerCmd_t command, void *argument) break; } case CONTAINER_SWITCH_SUBTITLE:{ - ret = - container_ffmpeg_switch_subtitle(context, - (int *) argument); + ret = container_ffmpeg_switch_subtitle(context, (int *) argument); break; } case CONTAINER_INFO:{ @@ -1765,15 +1562,11 @@ static int Command(void *_context, ContainerCmd_t command, void *argument) break; } case CONTAINER_SWITCH_DVBSUBTITLE:{ - ret = - container_ffmpeg_switch_dvbsubtitle(context, - (int *) argument); + ret = container_ffmpeg_switch_dvbsubtitle(context, (int *) argument); break; } case CONTAINER_SWITCH_TELETEXT:{ - ret = - container_ffmpeg_switch_teletext(context, - (int *) argument); + ret = container_ffmpeg_switch_teletext(context, (int *) argument); break; } default: @@ -1787,8 +1580,7 @@ static int Command(void *_context, ContainerCmd_t command, void *argument) return ret; } -static char *FFMPEG_Capabilities[] = - { "avi", "mkv", "mp4", "ts", "mov", "flv", "flac", "mp3", "mpg", +static char *FFMPEG_Capabilities[] = { "avi", "mkv", "mp4", "ts", "mov", "flv", "flac", "mp3", "mpg", "m2ts", "vob", "wmv", "wma", "asf", "mp2", "m4v", "m4a", "divx", "dat", "mpeg", "trp", "mts", "vdr", "ogg", "wav", "wtv", "ogm", "3gp", NULL }; diff --git a/libeplayer3/include/common.h b/libeplayer3/include/common.h index 452dffb..840bcf3 100644 --- a/libeplayer3/include/common.h +++ b/libeplayer3/include/common.h @@ -14,6 +14,5 @@ typedef struct Context_s { ManagerHandler_t *manager; } Context_t; -int container_ffmpeg_update_tracks(Context_t * context, char *filename, - int initial); +int container_ffmpeg_update_tracks(Context_t * context, char *filename, int initial); #endif diff --git a/libeplayer3/include/pes.h b/libeplayer3/include/pes.h index 6af0050..12c274f 100644 --- a/libeplayer3/include/pes.h +++ b/libeplayer3/include/pes.h @@ -26,8 +26,7 @@ #define VC1_VIDEO_PES_START_CODE 0xfd #define AAC_AUDIO_PES_START_CODE 0xcf -int InsertPesHeader(unsigned char *data, int size, unsigned char stream_id, - unsigned long long int pts, int pic_start_code); +int InsertPesHeader(unsigned char *data, int size, unsigned char stream_id, unsigned long long int pts, int pic_start_code); int InsertVideoPrivateDataHeader(unsigned char *data, int payload_size); #endif diff --git a/libeplayer3/include/playback.h b/libeplayer3/include/playback.h index 64f6f06..3179d43 100644 --- a/libeplayer3/include/playback.h +++ b/libeplayer3/include/playback.h @@ -3,14 +3,15 @@ #include typedef enum { PLAYBACK_OPEN, PLAYBACK_CLOSE, PLAYBACK_PLAY, PLAYBACK_STOP, - PLAYBACK_PAUSE, PLAYBACK_CONTINUE, PLAYBACK_FLUSH, PLAYBACK_TERM, - PLAYBACK_FASTFORWARD, PLAYBACK_SEEK, PLAYBACK_SEEK_ABS, - PLAYBACK_PTS, PLAYBACK_LENGTH, PLAYBACK_SWITCH_AUDIO, - PLAYBACK_SWITCH_SUBTITLE, PLAYBACK_INFO, PLAYBACK_SLOWMOTION, - PLAYBACK_FASTBACKWARD, PLAYBACK_GET_FRAME_COUNT, - PLAYBACK_SWITCH_TELETEXT, PLAYBACK_SWITCH_DVBSUBTITLE, - PLAYBACK_FRAMEBUFFER_LOCK, - PLAYBACK_FRAMEBUFFER_UNLOCK } PlaybackCmd_t; + PLAYBACK_PAUSE, PLAYBACK_CONTINUE, PLAYBACK_FLUSH, PLAYBACK_TERM, + PLAYBACK_FASTFORWARD, PLAYBACK_SEEK, PLAYBACK_SEEK_ABS, + PLAYBACK_PTS, PLAYBACK_LENGTH, PLAYBACK_SWITCH_AUDIO, + PLAYBACK_SWITCH_SUBTITLE, PLAYBACK_INFO, PLAYBACK_SLOWMOTION, + PLAYBACK_FASTBACKWARD, PLAYBACK_GET_FRAME_COUNT, + PLAYBACK_SWITCH_TELETEXT, PLAYBACK_SWITCH_DVBSUBTITLE, + PLAYBACK_FRAMEBUFFER_LOCK, + PLAYBACK_FRAMEBUFFER_UNLOCK +} PlaybackCmd_t; typedef struct PlaybackHandler_s { char *Name; diff --git a/libeplayer3/include/subtitle.h b/libeplayer3/include/subtitle.h index 0737a47..eaa9e46 100644 --- a/libeplayer3/include/subtitle.h +++ b/libeplayer3/include/subtitle.h @@ -33,8 +33,7 @@ Style: Default,Arial,64,16777215,0,16777215,0,0,0,2,2,2,2,20,20,10,0\n\n\ [Events]\n\ Format: Marked, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text\n\n\n" -static inline unsigned char *text_to_ass(char *text, long long int pts, - double duration) +static inline unsigned char *text_to_ass(char *text, long long int pts, double duration) { char buf[1024]; unsigned int x, pos = 0; @@ -64,9 +63,7 @@ static inline unsigned char *text_to_ass(char *text, long long int pts, ec -= 6000 * em; es = ec / 100; ec -= 100 * es; - snprintf(line, len, - "Dialogue: Marked=0,%d:%02d:%02d.%02d,%d:%02d:%02d.%02d,Default,NTP,0000,0000,0000,!Effect,%s\n", - sh, sm, ss, sc, eh, em, es, ec, buf); + snprintf(line, len, "Dialogue: Marked=0,%d:%02d:%02d.%02d,%d:%02d:%02d.%02d,Default,NTP,0000,0000,0000,!Effect,%s\n", sh, sm, ss, sc, eh, em, es, ec, buf); return (unsigned char *) line;