Ticket #7410: convertto16bitsaudio-fixes.diff
File convertto16bitsaudio-fixes.diff, 5.8 KB (added by , 15 years ago) |
---|
-
mythtv/libs/libmythtv/avformatdecoder.cpp
459 459 itv(NULL), 460 460 selectedVideoIndex(-1), 461 461 // Audio 462 audioSamples(NULL), 462 audioSamples(NULL), audioSamples2(NULL), 463 reformat_ctx(NULL), 463 464 allow_ac3_passthru(false), allow_dts_passthru(false), 464 465 disable_passthru(false), max_channels(2), 465 466 dummy_frame(NULL), … … 474 475 params.prealloced_context = 1; 475 476 audioSamples = (short int *)av_mallocz(AVCODEC_MAX_AUDIO_FRAME_SIZE * 476 477 sizeof(*audioSamples)); 478 audioSamples2 = (short int *)av_mallocz(AVCODEC_MAX_AUDIO_FRAME_SIZE * 479 sizeof(*audioSamples2)); 477 480 ccd608->SetIgnoreTimecode(true); 478 481 479 482 bool debug = (bool)(print_verbose_messages & VB_LIBAV); … … 509 512 delete m_h264_parser; 510 513 511 514 av_freep((void *)&audioSamples); 515 av_freep((void *)&audioSamples2); 512 516 513 517 if (dummy_frame) 514 518 { … … 3665 3669 case CODEC_TYPE_AUDIO: 3666 3670 { 3667 3671 bool reselectAudioTrack = false; 3672 char *s; 3668 3673 3669 3674 /// HACK HACK HACK -- begin See #3731 3670 3675 if (!GetNVP()->HasAudioIn()) … … 3691 3696 (curstream->codec->codec_id == CODEC_ID_DTS)); 3692 3697 bool using_passthru = do_ac3_passthru || do_dts_passthru; 3693 3698 3694 /// XXX HACK: set sample format to signed 16 bit3695 if (curstream->codec->codec_id == CODEC_ID_TRUEHD)3696 curstream->codec->sample_fmt = SAMPLE_FMT_S16;3697 3698 3699 // detect channels on streams that need 3699 3700 // to be decoded before we can know this 3700 3701 bool already_decoded = false; … … 3768 3769 3769 3770 avcodeclock.lock(); 3770 3771 data_size = 0; 3772 s = (char *)audioSamples; 3773 3771 3774 if (audioOut.do_passthru) 3772 3775 { 3773 3776 data_size = pkt->size; … … 3794 3797 &data_size, ptr, len); 3795 3798 } 3796 3799 3800 // Convert sample format if required (Myth only handles 8 and 16 bits audio) 3801 if (ctx->sample_fmt != SAMPLE_FMT_S16 && ctx->sample_fmt != SAMPLE_FMT_U8) 3802 { 3803 if (reformat_ctx) 3804 av_audio_convert_free(reformat_ctx); 3805 reformat_ctx = av_audio_convert_alloc(SAMPLE_FMT_S16, 1, 3806 ctx->sample_fmt, 1, 3807 NULL, 0); 3808 if (!reformat_ctx) 3809 { 3810 VERBOSE(VB_PLAYBACK, QString("Cannot convert %1 sample format to %2 sample format") 3811 .arg(avcodec_get_sample_fmt_name(ctx->sample_fmt)) 3812 .arg(avcodec_get_sample_fmt_name(SAMPLE_FMT_S16))); 3813 3814 avcodeclock.unlock(); 3815 have_err = true; 3816 continue; 3817 } 3818 3819 const void *ibuf[6] = {audioSamples}; 3820 void *obuf[6] = {audioSamples2}; 3821 int istride[6] = {av_get_bits_per_sample_format(ctx->sample_fmt)/8}; 3822 int ostride[6] = {2}; 3823 int len = data_size/istride[0]; 3824 if (av_audio_convert(reformat_ctx, obuf, ostride, 3825 ibuf, istride, len) < 0) 3826 { 3827 VERBOSE(VB_PLAYBACK, "av_audio_convert() failed"); 3828 3829 avcodeclock.unlock(); 3830 have_err = true; 3831 continue; 3832 } 3833 3834 data_size = len * 2; 3835 s = (char *)audioSamples2; 3836 } 3837 3797 3838 // When decoding some audio streams the number of 3798 3839 // channels, etc isn't known until we try decoding it. 3799 3840 if ((ctx->sample_rate != audioOut.sample_rate) || … … 3840 3881 if (audSubIdx != -1) 3841 3882 { 3842 3883 extract_mono_channel(audSubIdx, &audioOut, 3843 (char*)audioSamples, data_size);3884 s, data_size); 3844 3885 } 3845 3886 3846 GetNVP()->AddAudioData( 3847 (char *)audioSamples, data_size, temppts); 3887 GetNVP()->AddAudioData(s, data_size, temppts); 3848 3888 3849 3889 total_decoded_audio += data_size; 3850 3890 -
mythtv/libs/libmythtv/avformatdecoder.h
15 15 #include "frame.h" 16 16 #include "avcodec.h" 17 17 #include "avformat.h" 18 #include "audioconvert.h" 18 19 } 19 20 20 21 #include "avfringbuffer.h" … … 256 257 257 258 // Audio 258 259 short int *audioSamples; 260 short int *audioSamples2; 261 AVAudioConvert *reformat_ctx; 262 259 263 bool allow_ac3_passthru; 260 264 bool allow_dts_passthru; 261 265 bool disable_passthru;