Ticket #7410: convertto16bitsaudio-fixes.diff

File convertto16bitsaudio-fixes.diff, 5.8 KB (added by JYA, 15 years ago)

Convert non 16 bits audio into 16 bits audio for playback ; 0.22-fixes patch

  • mythtv/libs/libmythtv/avformatdecoder.cpp

     
    459459      itv(NULL),
    460460      selectedVideoIndex(-1),
    461461      // Audio
    462       audioSamples(NULL),
     462      audioSamples(NULL),           audioSamples2(NULL),
     463      reformat_ctx(NULL),
    463464      allow_ac3_passthru(false),    allow_dts_passthru(false),
    464465      disable_passthru(false),      max_channels(2),
    465466      dummy_frame(NULL),
     
    474475    params.prealloced_context = 1;
    475476    audioSamples = (short int *)av_mallocz(AVCODEC_MAX_AUDIO_FRAME_SIZE *
    476477                                           sizeof(*audioSamples));
     478    audioSamples2 = (short int *)av_mallocz(AVCODEC_MAX_AUDIO_FRAME_SIZE *
     479                                           sizeof(*audioSamples2));
    477480    ccd608->SetIgnoreTimecode(true);
    478481
    479482    bool debug = (bool)(print_verbose_messages & VB_LIBAV);
     
    509512    delete m_h264_parser;
    510513
    511514    av_freep((void *)&audioSamples);
     515    av_freep((void *)&audioSamples2);
    512516
    513517    if (dummy_frame)
    514518    {
     
    36653669                case CODEC_TYPE_AUDIO:
    36663670                {
    36673671                    bool reselectAudioTrack = false;
     3672                    char *s;
    36683673
    36693674                    /// HACK HACK HACK -- begin See #3731
    36703675                    if (!GetNVP()->HasAudioIn())
     
    36913696                         (curstream->codec->codec_id == CODEC_ID_DTS));
    36923697                    bool using_passthru = do_ac3_passthru || do_dts_passthru;
    36933698
    3694                     /// XXX HACK: set sample format to signed 16 bit
    3695                     if (curstream->codec->codec_id == CODEC_ID_TRUEHD)
    3696                         curstream->codec->sample_fmt = SAMPLE_FMT_S16;
    3697 
    36983699                    // detect channels on streams that need
    36993700                    // to be decoded before we can know this
    37003701                    bool already_decoded = false;
     
    37683769
    37693770                    avcodeclock.lock();
    37703771                    data_size = 0;
     3772                    s = (char *)audioSamples;
     3773
    37713774                    if (audioOut.do_passthru)
    37723775                    {
    37733776                        data_size = pkt->size;
     
    37943797                                                        &data_size, ptr, len);
    37953798                        }
    37963799
     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
    37973838                        // When decoding some audio streams the number of
    37983839                        // channels, etc isn't known until we try decoding it.
    37993840                        if ((ctx->sample_rate != audioOut.sample_rate) ||
     
    38403881                    if (audSubIdx != -1)
    38413882                    {
    38423883                        extract_mono_channel(audSubIdx, &audioOut,
    3843                                              (char*)audioSamples, data_size);
     3884                                             s, data_size);
    38443885                    }
    38453886
    3846                     GetNVP()->AddAudioData(
    3847                         (char *)audioSamples, data_size, temppts);
     3887                    GetNVP()->AddAudioData(s, data_size, temppts);
    38483888
    38493889                    total_decoded_audio += data_size;
    38503890
  • mythtv/libs/libmythtv/avformatdecoder.h

     
    1515#include "frame.h"
    1616#include "avcodec.h"
    1717#include "avformat.h"
     18#include "audioconvert.h"
    1819}
    1920
    2021#include "avfringbuffer.h"
     
    256257
    257258    // Audio
    258259    short int        *audioSamples;
     260    short int        *audioSamples2;
     261    AVAudioConvert   *reformat_ctx;
     262
    259263    bool              allow_ac3_passthru;
    260264    bool              allow_dts_passthru;
    261265    bool              disable_passthru;