Ticket #5580: mythmusic_ffmpeg.diff

File mythmusic_ffmpeg.diff, 31.3 KB (added by stuartm, 15 years ago)
  • mythplugins/mythmusic/mythmusic/mythmusic.pro

     
    66!exists( config.pro ) {
    77   error(Missing config.pro: please run the configure script)
    88}
    9  
     9
    1010INCLUDEPATH *= /usr/include/cdda
    1111TEMPLATE = lib
    1212CONFIG += plugin thread
     
    2323# Input
    2424HEADERS += cddecoder.h cdrip.h constants.h databasebox.h
    2525HEADERS += decoder.h flacdecoder.h flacencoder.h maddecoder.h mainvisual.h
    26 HEADERS += metadata.h playbackbox.h playlist.h polygon.h 
     26HEADERS += metadata.h playbackbox.h playlist.h polygon.h
    2727HEADERS += streaminput.h synaesthesia.h encoder.h visualize.h avfdecoder.h
    2828HEADERS += treecheckitem.h vorbisdecoder.h vorbisencoder.h polygon.h
    2929HEADERS += bumpscope.h globalsettings.h lameencoder.h dbcheck.h
     
    3737HEADERS += filescanner.h libvisualplugin.h musicplayer.h miniplayer.h
    3838HEADERS += mythlistview-qt3.h mythlistbox-qt3.h
    3939
    40 SOURCES += cddecoder.cpp cdrip.cpp decoder.cpp 
    41 SOURCES += flacdecoder.cpp flacencoder.cpp maddecoder.cpp main.cpp
    42 SOURCES += mainvisual.cpp metadata.cpp playbackbox.cpp playlist.cpp 
     40SOURCES += cddecoder.cpp cdrip.cpp decoder.cpp
     41SOURCES += flacencoder.cpp main.cpp
     42SOURCES += mainvisual.cpp metadata.cpp playbackbox.cpp playlist.cpp
    4343SOURCES += streaminput.cpp encoder.cpp dbcheck.cpp
    44 SOURCES += synaesthesia.cpp treecheckitem.cpp vorbisdecoder.cpp lameencoder.cpp
     44SOURCES += synaesthesia.cpp treecheckitem.cpp lameencoder.cpp
    4545SOURCES += vorbisencoder.cpp visualize.cpp bumpscope.cpp globalsettings.cpp
    4646SOURCES += databasebox.cpp genres.cpp
    47 SOURCES += metaio.cpp metaiotaglib.cpp vcedit.c metaiooggvorbiscomment.cpp 
     47SOURCES += metaio.cpp metaiotaglib.cpp vcedit.c metaiooggvorbiscomment.cpp
    4848SOURCES += metaioflacvorbiscomment.cpp metaioavfcomment.cpp
    4949SOURCES += goom/filters.c goom/goom_core.c goom/graphic.c goom/tentacle3d.c
    50 SOURCES += goom/ifs.c goom/ifs_display.c goom/lines.c goom/surf3d.c 
     50SOURCES += goom/ifs.c goom/ifs_display.c goom/lines.c goom/surf3d.c
    5151SOURCES += goom/zoom_filter_mmx.c goom/zoom_filter_xmmx.c goom/mythgoom.cpp
    5252SOURCES += avfdecoder.cpp editmetadata.cpp smartplaylist.cpp search.cpp
    5353SOURCES += treebuilders.cpp importmusic.cpp directoryfinder.cpp
     
    7171
    7272
    7373#The following line was inserted by qt3to4
    74 QT += xml  sql opengl qt3support 
     74QT += xml  sql opengl qt3support
    7575
    7676include ( ../../libs-targetfix.pro )
  • mythplugins/mythmusic/mythmusic/aacdecoder.cpp

     
    33
    44        (c) 2003, 2004 Thor Sigvaldason and Isaac Richards
    55        Part of the mythTV project
    6        
     6
    77        aac decoder methods
    8        
     8
    99*/
    1010
    1111#include <faad.h>
     
    5050    {
    5151        return the_decoder_object->aacRead((char *)buffer, length);
    5252    }
    53     VERBOSE(VB_IMPORTANT, 
     53    VERBOSE(VB_IMPORTANT,
    5454            "read_callback called with no aacDecoder object assigned");
    5555    return 0;
    56    
     56
    5757}
    58    
     58
    5959uint32_t seek_callback(void *user_data, uint64_t position)
    6060{
    6161    aacDecoder *the_decoder_object = (aacDecoder*) user_data;
     
    6666    VERBOSE(VB_IMPORTANT,
    6767            "seek_callback called with no aacDecoder object assigned");
    6868    return 0;
    69 }       
     69}
    7070
    7171
    7272
     
    7676
    7777
    7878
    79 aacDecoder::aacDecoder(const QString &file, DecoderFactory *d, QIODevice *i, 
    80                        AudioOutput *o) 
     79aacDecoder::aacDecoder(const QString &file, DecoderFactory *d, QIODevice *i,
     80                       AudioOutput *o)
    8181          : Decoder(d, i, o)
    8282{
    8383    filename = file;
     
    9696    output_buf = 0;
    9797    output_bytes = 0;
    9898    output_at = 0;
    99    
     99
    100100    mp4_file_flag = false;
    101101    mp4_callback = NULL;
    102102    timescale = 0;
     
    124124{
    125125    ulong min = final ? 0 : bks;
    126126
    127     while ((!done && !finish && seekTime <= 0) && output_bytes > min) 
     127    while ((!done && !finish && seekTime <= 0) && output_bytes > min)
    128128    {
    129         if (user_stop || finish) 
     129        if (user_stop || finish)
    130130        {
    131131            inited = FALSE;
    132132            done = TRUE;
    133         } 
    134         else 
     133        }
     134        else
    135135        {
    136136            ulong sz = output_bytes < bks ? output_bytes : bks;
    137137
     
    147147                lock();
    148148                done = user_stop;
    149149              }
    150            
     150
    151151        }
    152152    }
    153153}
     
    163163    framesize = 0;
    164164    seekTime = -1.0;
    165165    totalTime = 0.0;
    166    
     166
    167167    mp4_file_flag = false;
    168168
    169169    if (! input())
     
    172172        return false;
    173173    }
    174174
    175    
     175
    176176    if (!output_buf) {
    177177        output_buf = new char[globalBufferSize];
    178178    }
     
    198198      error("couldn't seek in input");
    199199        return false;
    200200    }
    201    
    202201
     202
    203203    //
    204204    //  figure out if it's an mp4 file (aac in a mp4 wrapper a la Apple) or
    205205    //  just a pure aac file.
    206206    //
    207    
     207
    208208    mp4_file_flag = false;
    209209    char header_buffer[8];
    210210    input()->readBlock(header_buffer, 8);
    211    
     211
    212212    //
    213213    //  Seek back to the begining, otherwise the decoder gets totally confused.
    214214    //
    215    
     215
    216216    input()->at(0);
    217    
     217
    218218    if (
    219             header_buffer[4] == 'f' && 
    220             header_buffer[5] == 't' && 
    221             header_buffer[6] == 'y' && 
     219            header_buffer[4] == 'f' &&
     220            header_buffer[5] == 't' &&
     221            header_buffer[6] == 'y' &&
    222222            header_buffer[7] == 'p'
    223223      )
    224224    {
    225225        //
    226         //  It's an mp4/m4a (iTunes file) ... 
     226        //  It's an mp4/m4a (iTunes file) ...
    227227        //
    228228        mp4_file_flag = true;
    229229        return initializeMP4();
     
    236236        inited = false;
    237237        return false;
    238238    }
    239    
     239
    240240    input()->close();
    241241    inited = false;
    242242    return false;
     
    253253    mp4_callback->read = read_callback;
    254254    mp4_callback->seek = seek_callback;
    255255    mp4_callback->user_data = this;
    256    
     256
    257257    //
    258258    //  Open decoder library (?)
    259259    //
    260    
     260
    261261    decoder_handle = faacDecOpen();
    262262
    263263    //
    264264    //  Set configuration
    265265    //
    266    
     266
    267267    faacDecConfigurationPtr config = faacDecGetCurrentConfiguration(decoder_handle);
    268268    config->outputFormat = FAAD_FMT_16BIT;
    269269    config->downMatrix = 0; // if 1, we could downmix 5.1 to 2 ... apparently
    270270    config->dontUpSampleImplicitSBR = 1;
    271271    faacDecSetConfiguration(decoder_handle, config);
    272                    
     272
    273273    //
    274     //  Open the mp4 input file 
    275     //                   
     274    //  Open the mp4 input file
     275    //
    276276
    277277    mp4_input_file = mp4ff_open_read(mp4_callback);
    278278    if (!mp4_input_file)
     
    305305    uint buffer_size;
    306306
    307307    mp4ff_get_decoder_config(
    308                                 mp4_input_file, 
    309                                 aac_track_number, 
    310                                 &buffer, 
     308                                mp4_input_file,
     309                                aac_track_number,
     310                                &buffer,
    311311                                &buffer_size
    312312                            );
    313313// some linux distros (gentoo, debian) modify the faad2 api with stdint.h types
     
    335335
    336336    timescale = mp4ff_time_scale(mp4_input_file, aac_track_number);
    337337    framesize = 1024;
    338            
     338
    339339    //
    340340    //  Fiddle with the default frame size if the data appears to need it
    341     // 
     341    //
    342342
    343343    mp4AudioSpecificConfig mp4ASC;
    344344    if (buffer)
     
    354354    //
    355355    //  Extract some information about the content
    356356    //
    357    
     357
    358358    long samples = mp4ff_num_samples(mp4_input_file, aac_track_number);
    359359    float f = 1024.0;
    360360    float seconds;
    361    
     361
    362362    if (mp4ASC.sbr_present_flag == 1)
    363363    {
    364364        f = f * 2.0;
    365365    }
    366    
     366
    367367    seconds = (float)samples*(float)(f-1.0)/(float)mp4ASC.samplingFrequency;
    368368
    369369    totalTime = seconds;
     
    374374    {
    375375        bitrate = mp4ff_get_avg_bitrate(mp4_input_file, aac_track_number) / 1000;
    376376    }
    377    
     377
    378378    //
    379379    //  Check we got same answers from mp4ASC
    380380    //
     
    437437
    438438    //
    439439    //  No AAC tracks
    440     // 
     440    //
    441441    return -1;
    442442}
    443443
     
    470470
    471471    lock();
    472472
    473     if (!inited) 
     473    if (!inited)
    474474    {
    475475      error("aacDecoder: run() called without being init'd");
    476476        unlock();
     
    496496    uchar *buffer;
    497497    uint  buffer_size;
    498498
    499     while (!done && !finish && !user_stop) 
     499    while (!done && !finish && !user_stop)
    500500    {
    501501        lock();
    502502
    503503        ++current_sample;
    504         if (seekTime >= 0.0) 
     504        if (seekTime >= 0.0)
    505505        {
    506506            //
    507507            //  Crap ... seek ... well, this is approximately correct
    508             //       
     508            //
    509509
    510510            current_sample = (long int) (((double)(seekTime / totalTime)) * total_numb_samples);
    511511            seekTime = -1.0;
    512512        }
    513        
     513
    514514        if (current_sample >= total_numb_samples)
    515515        {
    516516            //
    517517            //  We're done ... make sure we play all the remaining output
    518518            //
    519            
     519
    520520            flush(TRUE);
    521521
    522522            if (output())
     
    539539            buffer_size = 0;
    540540
    541541            int rc = mp4ff_read_sample(
    542                                         mp4_input_file, 
    543                                         aac_track_number, 
    544                                         current_sample, 
    545                                         &buffer, 
     542                                        mp4_input_file,
     543                                        aac_track_number,
     544                                        current_sample,
     545                                        &buffer,
    546546                                        &buffer_size
    547547                                      );
    548548            if (rc == 0)
     
    552552            }
    553553            else
    554554            {
    555            
     555
    556556                faacDecFrameInfo frame_info;
    557557                void *sample_buffer = faacDecDecode(
    558                                                     decoder_handle, 
    559                                                     &frame_info, 
    560                                                     buffer, 
     558                                                    decoder_handle,
     559                                                    &frame_info,
     560                                                    buffer,
    561561                                                    buffer_size
    562562                                                   );
    563            
     563
    564564                sample_count = frame_info.samples;
    565565
    566566                //
     
    568568                //  to the output (after checking we're not going to exceed
    569569                //  the output buffer size)
    570570                //
    571                
     571
    572572                if (((sample_count * 2) + output_at ) >= globalBufferSize)
    573573                {
    574574                    error("aacDecoder: gloablBufferSize too small, "
     
    576576                          "sound like crap)");
    577577                    sample_count = ((globalBufferSize - output_at) / 2) - 100;
    578578                }
    579            
     579
    580580                char *char_buffer = (char *)sample_buffer;
    581581                short *sample_buffer16 = (short*)char_buffer;
    582582                for(uint i = 0; i < sample_count; i++)
     
    584584                    output_buf[output_at + (i*2)]     = (char)(sample_buffer16[i] & 0xFF);
    585585                    output_buf[output_at + (i*2) + 1] = (char)((sample_buffer16[i] >> 8) & 0xFF);
    586586                }
    587            
     587
    588588                if (sample_count > 0)
    589589                {
    590590                    output_at += sample_count * 2;
     
    595595                        if (bitrate)
    596596                        {
    597597                            output()->SetSourceBitrate(bitrate);
    598                         } 
    599                         else 
     598                        }
     599                        else
    600600                        {
    601601                            output()->SetSourceBitrate(
    602602                                (int) ((float) (frame_info.bytesconsumed * 8) /
    603                                        (frame_info.samples / 
    604                                         frame_info.num_front_channels) 
     603                                       (frame_info.samples /
     604                                        frame_info.num_front_channels)
    605605                                * frame_info.samplerate) / 1000);
    606606                        }
    607607
    608608                        flush();
    609609                    }
    610610                }
    611            
     611
    612612                if (buffer)
    613613                {
    614614                    free(buffer);
     
    656656        {
    657657            return 0;
    658658        }
    659         return read_result; 
     659        return read_result;
    660660    }
    661661    error("aacDecoder: aacRead() was called, but there is no input");
    662662    return 0;
     
    691691
    692692const QString &aacDecoderFactory::extension() const
    693693{
    694     static QString ext(".m4a");
     694    static QString ext(".aac|.m4a");
    695695    return ext;
    696696}
    697697
     
    702702    return desc;
    703703}
    704704
    705 Decoder *aacDecoderFactory::create(const QString &file, QIODevice *input, 
     705Decoder *aacDecoderFactory::create(const QString &file, QIODevice *input,
    706706                                  AudioOutput *output, bool deletable)
    707707{
    708708
     
    710710        return new aacDecoder(file, this, input, output);
    711711
    712712    static aacDecoder *decoder = 0;
    713     if (!decoder) 
     713    if (!decoder)
    714714    {
    715715        decoder = new aacDecoder(file, this, input, output);
    716     } 
    717     else 
     716    }
     717    else
    718718    {
    719719        decoder->setInput(input);
    720720        decoder->setOutput(output);
  • mythplugins/mythmusic/mythmusic/decoder.h

     
    8989    static QStringList all();
    9090    static bool supports(const QString &);
    9191    static void registerFactory(DecoderFactory *);
    92     static Decoder *create(const QString &, QIODevice *, AudioOutput *, 
     92    static Decoder *create(const QString &, QIODevice *, AudioOutput *,
    9393                           bool = FALSE);
    9494    static void SetLocationFormatUseTags(void);
    9595
     
    126126    virtual ~DecoderFactory() {}
    127127};
    128128
    129 class VorbisDecoderFactory : public DecoderFactory
    130 {
    131 public:
    132     bool supports(const QString &) const;
    133     const QString &extension() const;
    134     const QString &description() const;
    135     Decoder *create(const QString &, QIODevice *, AudioOutput *, bool);
    136 };
    137 
    138 class MadDecoderFactory : public DecoderFactory
    139 {
    140 public:
    141     bool supports(const QString &) const;
    142     const QString &extension() const;
    143     const QString &description() const;
    144     Decoder *create(const QString &, QIODevice *, AudioOutput *, bool);
    145 };
    146 
    147129class CdDecoderFactory : public DecoderFactory
    148130{
    149131public:
     
    153135    Decoder *create(const QString &, QIODevice *, AudioOutput *, bool);
    154136};
    155137
    156 class FlacDecoderFactory : public DecoderFactory
    157 {
    158 public:
    159     bool supports(const QString &) const;
    160     const QString &extension() const;
    161     const QString &description() const;
    162     Decoder *create(const QString &, QIODevice *, AudioOutput *, bool);
    163 };
    164 
    165138class avfDecoderFactory : public DecoderFactory
    166139{
    167140public:
  • mythplugins/mythmusic/mythmusic/decoder.cpp

     
    2020
    2121#include <mythtv/mythcontext.h>
    2222
    23 DecoderEvent* DecoderEvent::clone() 
    24 { 
     23DecoderEvent* DecoderEvent::clone()
     24{
    2525    DecoderEvent *result = new DecoderEvent(*this);
    2626
    2727    if (error_msg)
     
    5757    unlock();
    5858}
    5959
    60 void Decoder::error(const QString &e) 
     60void Decoder::error(const QString &e)
    6161{
    6262    QString *str = new QString(e.toUtf8());
    6363    DecoderEvent ev(str);
     
    9898
    9999
    100100/** \fn Decoder::getMetadata(void)
    101  *  \brief Get the metadata  for \p filename 
     101 *  \brief Get the metadata  for \p filename
    102102 *
    103103 *  First tries to read the metadata from the database. If there
    104104 *  is no database entry, it'll call \p Decoder::readMetadata.
     
    127127 *  instance of the appropriate MetaIO subtype. It is used by \p
    128128 *  Decoder::getMetadata, \p Decoder::readMetadata and \p
    129129 *  Decoder::commitMetadata.
    130  *       
     130 *
    131131 *  The default implementation returns a NULL pointer, which
    132132 *  essentially means, that if the decoder does not overrider this
    133133 *  method or all of the users (see previous paragraph), files
     
    182182
    183183static Q3PtrList<DecoderFactory> *factories = 0;
    184184
    185 static void checkFactories() 
     185static void checkFactories()
    186186{
    187     if (!factories) 
     187    if (!factories)
    188188    {
    189189        factories = new Q3PtrList<DecoderFactory>;
    190190
    191         Decoder::registerFactory(new VorbisDecoderFactory);
    192         Decoder::registerFactory(new MadDecoderFactory);
    193         Decoder::registerFactory(new FlacDecoderFactory);
    194191#ifndef USING_MINGW
    195192        Decoder::registerFactory(new CdDecoderFactory);
    196193#endif // USING_MINGW
     
    207204
    208205    QStringList l;
    209206    DecoderFactory *fact = factories->first();
    210     while (fact) 
     207    while (fact)
    211208    {
    212209        l << fact->description();
    213210        fact = factories->next();
     
    221218    checkFactories();
    222219
    223220    DecoderFactory *fact = factories->first();
    224     while (fact) 
     221    while (fact)
    225222    {
    226223        if (fact->supports(source))
    227224            return TRUE;
     
    245242    Decoder *decoder = 0;
    246243
    247244    DecoderFactory *fact = factories->first();
    248     while (fact) 
     245    while (fact)
    249246    {
    250         if (fact->supports(source)) 
     247        if (fact->supports(source))
    251248        {
    252249            decoder = fact->create(source, input, output, deletable);
    253250            break;
  • mythplugins/mythmusic/mythmusic/avfdecoder.cpp

     
    22    MythTV WMA Decoder
    33    Written by Kevin Kuphal
    44
    5     Special thanks to 
     5    Special thanks to
    66       ffmpeg team for libavcodec and libavformat
    77       qemacs team for their av support which I used to understand the libraries
    88       getid3.sourceforget.net project for the ASF information used here
    9        
    10     This library decodes Windows Media (WMA/ASF) files into PCM data
    11     returned to the MythMusic output buffer. 
    129
     10    This library decodes Windows Media (WMA/ASF) files into PCM data
     11    returned to the MythMusic output buffer.
     12
    1313    Revision History
    1414        - Initial release
    1515        - 1/9/2004 - Improved seek support
    1616*/
    1717
     18// C++ headers
    1819#include <iostream>
    1920#include <string>
    20 #include <qobject.h>
    21 #include <qiodevice.h>
    22 #include <qfile.h>
    2321
     22// QT headers
     23#include <QObject>
     24#include <QIODevice>
     25#include <QFile>
     26
     27// Myth headers
     28#include <mythtv/mythcontext.h>
     29#include <mythtv/audiooutput.h>
     30#include <mythtv/mythverbose.h>
     31
    2432using namespace std;
    2533
     34// Mythmusic Headers
    2635#include "avfdecoder.h"
    2736#include "constants.h"
    28 #include <mythtv/audiooutput.h>
    2937#include "metadata.h"
    3038#include "metaioavfcomment.h"
    3139
    32 #include <mythtv/mythcontext.h>
    3340
    34 avfDecoder::avfDecoder(const QString &file, DecoderFactory *d, QIODevice *i, 
    35                        AudioOutput *o) 
     41avfDecoder::avfDecoder(const QString &file, DecoderFactory *d, QIODevice *i,
     42                       AudioOutput *o)
    3643          : Decoder(d, i, o)
    3744{
    3845    filename = file;
     
    4754    bitrate = 0;
    4855    seekTime = -1.0;
    4956    totalTime = 0.0;
    50     chan = 0;
     57    m_channels = 0;
    5158    output_buf = 0;
    5259    output_bytes = 0;
    5360    output_at = 0;
    5461
    55     ic = NULL;
    56     oc = NULL;
    57     ifmt = NULL;
    58     ap = &params;
    59     pkt = &pkt1;
     62    m_inputContext = NULL;
     63    m_outputContext = NULL;
     64    m_inputFormat = NULL;
     65    m_outputFormat = NULL;
     66    m_ap = &m_params;
     67    m_pkt = &m_pkt1;
     68    m_decStream = NULL;
    6069}
    6170
    6271avfDecoder::~avfDecoder(void)
     
    8089{
    8190    ulong min = final ? 0 : bks;
    8291
    83     while ((!done && !finish && seekTime <= 0) && output_bytes > min) 
     92    while ((!done && !finish && seekTime <= 0) && output_bytes > min)
    8493    {
    85         if (user_stop || finish) 
     94        if (user_stop || finish)
    8695        {
    8796            inited = FALSE;
    8897            done = TRUE;
    89         } 
    90         else 
     98        }
     99        else
    91100        {
    92101            ulong sz = output_bytes < bks ? output_bytes : bks;
    93102
    94             int samples = (sz*8)/(chan*16);
     103            int samples = (sz*8)/(m_channels*16);
    95104            if (output()->AddSamples(output_buf, samples, -1))
    96105            {
    97106                output_bytes -= sz;
     
    109118
    110119bool avfDecoder::initialize()
    111120{
     121    VERBOSE(VB_GENERAL, "Initialising");
    112122    bks = blockSize();
    113123
    114124    inited = user_stop = done = finish = FALSE;
    115125    len = freq = bitrate = 0;
    116     stat = chan = 0;
     126    stat = m_channels = 0;
    117127    seekTime = -1.0;
    118128    totalTime = 0.0;
    119129
    120130    filename = ((QFile *)input())->name();
    121    
     131
    122132    if (!output_buf)
    123133        output_buf = new char[globalBufferSize];
    124134    output_at = 0;
     
    130140
    131141    // open the media file
    132142    // this should populate the input context
    133     if (av_open_input_file(&ic, filename, ifmt, 0, ap) < 0)
    134         return FALSE;   
     143    if (av_open_input_file(&m_inputContext, filename, m_inputFormat, 0, m_ap) < 0)
     144    {
     145        deinit();
     146        return FALSE;
     147    }
    135148
    136149    // determine the stream format
    137150    // this also populates information needed for metadata
    138     if (av_find_stream_info(ic) < 0)
     151    if (av_find_stream_info(m_inputContext) < 0)
     152    {
     153        deinit();
    139154        return FALSE;
     155    }
    140156
    141157    // Store the audio codec of the stream
    142     audio_dec = ic->streams[0]->codec;
     158    m_audioDec = m_inputContext->streams[0]->codec;
    143159
    144160    // Store the input format of the context
    145     ifmt = ic->iformat;
     161    m_inputFormat = m_inputContext->iformat;
    146162
    147163    // Determine the output format
    148164    // Given we are outputing to a sound card, this will always
    149165    // be a PCM format
     166
    150167#ifdef WORDS_BIGENDIAN
    151     fmt = guess_format("s16be", NULL, NULL);
     168    m_outputFormat = guess_format("s16be", NULL, NULL);
    152169#else
    153     fmt = guess_format("s16le", NULL, NULL);
     170    m_outputFormat = guess_format("s16le", NULL, NULL);
    154171#endif
    155     if (!fmt)
     172
     173    if (!m_outputFormat)
    156174    {
    157175        VERBOSE(VB_IMPORTANT, "avfDecoder.o - failed to get output format");
     176        deinit();
    158177        return FALSE;
    159178    }
    160179
    161180    // Populate the output context
    162181    // Create the output stream and attach to output context
    163182    // Set various parameters to match the input format
    164     oc = (AVFormatContext *)av_mallocz(sizeof(AVFormatContext));
    165     oc->oformat = fmt;
     183    m_outputContext = (AVFormatContext *)av_mallocz(sizeof(AVFormatContext));
     184    m_outputContext->oformat = m_outputFormat;
    166185
    167     dec_st = av_new_stream(oc,0);
    168     dec_st->codec->codec_type = CODEC_TYPE_AUDIO;
    169     dec_st->codec->codec_id = oc->oformat->audio_codec;
    170     dec_st->codec->sample_rate = audio_dec->sample_rate;
    171     dec_st->codec->channels = audio_dec->channels;
    172     dec_st->codec->bit_rate = audio_dec->bit_rate;
    173     av_set_parameters(oc, NULL);
     186    m_decStream = av_new_stream(m_outputContext,0);
     187    m_decStream->codec->codec_type = CODEC_TYPE_AUDIO;
     188    m_decStream->codec->codec_id = m_outputContext->oformat->audio_codec;
     189    m_decStream->codec->sample_rate = m_audioDec->sample_rate;
     190    m_decStream->codec->channels = m_audioDec->channels;
     191    m_decStream->codec->bit_rate = m_audioDec->bit_rate;
     192    av_set_parameters(m_outputContext, NULL);
    174193
    175194    // Prepare the decoding codec
    176195    // The format is different than the codec
    177196    // While we could get fed a WAV file, it could contain a number
    178197    // of different codecs
    179     codec = avcodec_find_decoder(audio_dec->codec_id);
    180     if (!codec)
     198    m_codec = avcodec_find_decoder(m_audioDec->codec_id);
     199    if (!m_codec)
     200    {
     201        deinit();
    181202        return FALSE;
    182     if (avcodec_open(audio_dec,codec) < 0)
     203    }
     204    if (avcodec_open(m_audioDec,m_codec) < 0)
     205    {
     206        deinit();
    183207        return FALSE;
    184     totalTime = (ic->duration / AV_TIME_BASE) * 1000;
     208    }
     209    if (AV_TIME_BASE > 0)
     210        totalTime = (m_inputContext->duration / AV_TIME_BASE) * 1000;
    185211
    186     freq = audio_dec->sample_rate;
    187     chan = audio_dec->channels;
     212    freq = m_audioDec->sample_rate;
     213    m_channels = m_audioDec->channels;
    188214
     215    if (m_channels <= 0)
     216    {
     217        VERBOSE(VB_IMPORTANT, QString("AVCodecContext tells us %1 channel are "
     218                                      "available, this is bad, bailing.")
     219                                      .arg(m_channels));
     220        deinit();
     221        return false;
     222    }
     223
    189224    if (output())
    190225    {
    191226        const AudioSettings settings(
    192             16 /*bits*/, audio_dec->channels, audio_dec->sample_rate,
     227            16 /*bits*/, m_audioDec->channels, m_audioDec->sample_rate,
    193228            false /* AC3/DTS pass through */);
    194229        output()->Reconfigure(settings);
    195         output()->SetSourceBitrate(audio_dec->bit_rate);
     230        output()->SetSourceBitrate(m_audioDec->bit_rate);
    196231    }
    197232
    198233    inited = TRUE;
     
    206241
    207242void avfDecoder::deinit()
    208243{
     244    VERBOSE(VB_GENERAL, "De-initialising");
    209245    inited = user_stop = done = finish = FALSE;
    210246    len = freq = bitrate = 0;
    211     stat = chan = 0;
     247    stat = m_channels = 0;
    212248    setInput(0);
    213249    setOutput(0);
    214250
    215251    // Cleanup here
    216     if(ic)
     252    if(m_inputContext)
    217253    {
    218         av_close_input_file(ic);
    219         ic = NULL;
     254        av_close_input_file(m_inputContext);
     255        m_inputContext = NULL;
    220256    }
    221     if(oc)
     257    if(m_outputContext)
    222258    {
    223         av_free(oc);
    224         oc = NULL;
     259        av_free(m_outputContext);
     260        m_outputContext = NULL;
    225261    }
     262
     263    m_decStream = NULL;
     264    m_codec = NULL;
     265    m_audioEnc = m_audioDec = NULL;
     266    m_inputFormat = NULL;
     267    m_outputFormat = NULL;
    226268}
    227269
    228270void avfDecoder::run()
     
    232274
    233275    lock();
    234276
    235     if (!inited) 
     277    if (!inited)
    236278    {
    237279        unlock();
    238280        return;
     
    247289        dispatch(e);
    248290    }
    249291
    250     av_read_play(ic);
    251     while (!done && !finish && !user_stop) 
     292    av_read_play(m_inputContext);
     293    while (!done && !finish && !user_stop)
    252294    {
    253295        lock();
    254296
    255297        // Look to see if user has requested a seek
    256         if (seekTime >= 0.0) 
     298        if (seekTime >= 0.0)
    257299        {
    258300            VERBOSE(VB_GENERAL, QString("avfdecoder.o: seek time %1")
    259301                .arg(seekTime));
    260             if (av_seek_frame(ic, -1, (int64_t)(seekTime * AV_TIME_BASE), 0)
     302            if (av_seek_frame(m_inputContext, -1, (int64_t)(seekTime * AV_TIME_BASE), 0)
    261303                              < 0)
    262304            {
    263305                VERBOSE(VB_IMPORTANT, "Error seeking");
     
    267309        }
    268310
    269311        // Read a packet from the input context
    270         // if (av_read_packet(ic, pkt) < 0)
    271         if (av_read_frame(ic, pkt) < 0)
     312        // if (av_read_packet(m_inputContext, m_pkt) < 0)
     313        if (av_read_frame(m_inputContext, m_pkt) < 0)
    272314        {
    273315            VERBOSE(VB_IMPORTANT, "Read frame failed");
    274316            unlock();
     
    277319        }
    278320
    279321        // Get the pointer to the data and its length
    280         ptr = pkt->data;
    281         len = pkt->size;
     322        ptr = m_pkt->data;
     323        len = m_pkt->size;
    282324        unlock();
    283325
    284         while (len > 0 && !done && !finish && !user_stop && seekTime <= 0.0) 
     326        while (len > 0 && !done && !finish && !user_stop && seekTime <= 0.0)
    285327        {
    286328            lock();
    287329            // Decode the stream to the output codec
     
    289331            // data_size is the size in bytes of the frame
    290332            // ptr is the input buffer
    291333            // len is the size of the input buffer
    292             dec_len = avcodec_decode_audio(audio_dec, samples, &data_size,
    293                                            ptr, len);   
    294             if (dec_len < 0) 
     334            dec_len = avcodec_decode_audio(m_audioDec, samples, &data_size,
     335                                           ptr, len);
     336            if (dec_len < 0)
    295337            {
    296338                unlock();
    297339                break;
     
    300342            s = (char *)samples;
    301343            unlock();
    302344
    303             while (data_size > 0 && !done && !finish && !user_stop && 
    304                    seekTime <= 0.0) 
     345            while (data_size > 0 && !done && !finish && !user_stop &&
     346                   seekTime <= 0.0)
    305347             {
    306348                lock();
    307349                // Store and check the size
     
    339381            len -= dec_len;
    340382            unlock();
    341383        }
    342         av_free_packet(pkt);
     384        av_free_packet(m_pkt);
    343385    }
    344386
    345387    flush(TRUE);
    346     if (output())
     388
     389    if (output() && !user_stop)
    347390        output()->Drain();
    348391
    349392    if (finish)
     
    364407MetaIO* avfDecoder::doCreateTagger(void)
    365408{
    366409    return new MetaIOAVFComment();
    367 }   
     410}
    368411
    369412bool avfDecoderFactory::supports(const QString &source) const
    370413{
     
    380423
    381424const QString &avfDecoderFactory::extension() const
    382425{
    383     static QString ext(".wma|.wav");
     426    static QString ext(".mp3|.mp2|.ogg|.flac|.wma|.wav|.ac3|.oma|.omg|.atp|"
     427                       ".ra|.dts");
    384428    return ext;
    385429}
    386430
     
    390434    return desc;
    391435}
    392436
    393 Decoder *avfDecoderFactory::create(const QString &file, QIODevice *input, 
     437Decoder *avfDecoderFactory::create(const QString &file, QIODevice *input,
    394438                                  AudioOutput *output, bool deletable)
    395439{
    396440    if (deletable)
    397441        return new avfDecoder(file, this, input, output);
    398442
    399443    static avfDecoder *decoder = 0;
    400     if (!decoder) 
     444    if (!decoder)
    401445    {
    402446        decoder = new avfDecoder(file, this, input, output);
    403     } 
    404     else 
     447    }
     448    else
    405449    {
    406450        decoder->setInput(input);
    407451        decoder->setOutput(output);
  • mythplugins/mythmusic/mythmusic/main.cpp

     
    2323// MythMusic headers
    2424#include "decoder.h"
    2525#include "metadata.h"
    26 #include "maddecoder.h"
    27 #include "vorbisdecoder.h"
    2826#include "databasebox.h"
    2927#include "playbackbox.h"
    3028#include "playlist.h"
  • mythplugins/mythmusic/mythmusic/avfdecoder.h

     
    3737    unsigned int bks;
    3838    bool done, finish;
    3939    long len, freq, bitrate;
    40     int chan;
     40    int m_channels;
    4141    unsigned long output_size;
    4242    double totalTime, seekTime;
    4343
     
    4646    long int start;
    4747    long int end;
    4848
    49     AVOutputFormat *fmt;        // Encoding format (PCM)
    50     AVInputFormat *ifmt;        // Decoding format
    51     AVFormatParameters params;
    52     AVFormatParameters *ap;
    53     AVFormatContext *oc, *ic;
    54     AVStream *enc_st, *dec_st;
    55     AVCodec *codec, *enc_codec;         // Codec
    56     AVCodecContext *audio_enc, *audio_dec;
    57     AVPacket pkt1;
    58     AVPacket *pkt;
     49    AVOutputFormat *m_outputFormat; // Encoding format (PCM)
     50    AVInputFormat *m_inputFormat; // Decoding format
     51    AVFormatParameters m_params;
     52    AVFormatParameters *m_ap;
     53    AVFormatContext *m_outputContext, *m_inputContext;
     54    AVStream *m_decStream;
     55    AVCodec *m_codec; // Codec
     56    AVCodecContext *m_audioEnc, *m_audioDec;
     57    AVPacket m_pkt1;
     58    AVPacket *m_pkt;
    5959
    6060    int errcode;
    6161
  • mythplugins/mythmusic/mythmusic/filescanner.cpp

     
    1616
    1717// MythMusic headers
    1818#include "decoder.h"
    19 #include "maddecoder.h"
    20 #include "vorbisdecoder.h"
    2119#include "filescanner.h"
    2220#include "metadata.h"
    2321