Ticket #5580: mythmusic_ffmpeg.diff
File mythmusic_ffmpeg.diff, 31.3 KB (added by , 15 years ago) |
---|
-
mythplugins/mythmusic/mythmusic/mythmusic.pro
6 6 !exists( config.pro ) { 7 7 error(Missing config.pro: please run the configure script) 8 8 } 9 9 10 10 INCLUDEPATH *= /usr/include/cdda 11 11 TEMPLATE = lib 12 12 CONFIG += plugin thread … … 23 23 # Input 24 24 HEADERS += cddecoder.h cdrip.h constants.h databasebox.h 25 25 HEADERS += decoder.h flacdecoder.h flacencoder.h maddecoder.h mainvisual.h 26 HEADERS += metadata.h playbackbox.h playlist.h polygon.h 26 HEADERS += metadata.h playbackbox.h playlist.h polygon.h 27 27 HEADERS += streaminput.h synaesthesia.h encoder.h visualize.h avfdecoder.h 28 28 HEADERS += treecheckitem.h vorbisdecoder.h vorbisencoder.h polygon.h 29 29 HEADERS += bumpscope.h globalsettings.h lameencoder.h dbcheck.h … … 37 37 HEADERS += filescanner.h libvisualplugin.h musicplayer.h miniplayer.h 38 38 HEADERS += mythlistview-qt3.h mythlistbox-qt3.h 39 39 40 SOURCES += cddecoder.cpp cdrip.cpp decoder.cpp 41 SOURCES += flac decoder.cpp flacencoder.cpp maddecoder.cpp main.cpp42 SOURCES += mainvisual.cpp metadata.cpp playbackbox.cpp playlist.cpp 40 SOURCES += cddecoder.cpp cdrip.cpp decoder.cpp 41 SOURCES += flacencoder.cpp main.cpp 42 SOURCES += mainvisual.cpp metadata.cpp playbackbox.cpp playlist.cpp 43 43 SOURCES += streaminput.cpp encoder.cpp dbcheck.cpp 44 SOURCES += synaesthesia.cpp treecheckitem.cpp vorbisdecoder.cpplameencoder.cpp44 SOURCES += synaesthesia.cpp treecheckitem.cpp lameencoder.cpp 45 45 SOURCES += vorbisencoder.cpp visualize.cpp bumpscope.cpp globalsettings.cpp 46 46 SOURCES += databasebox.cpp genres.cpp 47 SOURCES += metaio.cpp metaiotaglib.cpp vcedit.c metaiooggvorbiscomment.cpp 47 SOURCES += metaio.cpp metaiotaglib.cpp vcedit.c metaiooggvorbiscomment.cpp 48 48 SOURCES += metaioflacvorbiscomment.cpp metaioavfcomment.cpp 49 49 SOURCES += 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 50 SOURCES += goom/ifs.c goom/ifs_display.c goom/lines.c goom/surf3d.c 51 51 SOURCES += goom/zoom_filter_mmx.c goom/zoom_filter_xmmx.c goom/mythgoom.cpp 52 52 SOURCES += avfdecoder.cpp editmetadata.cpp smartplaylist.cpp search.cpp 53 53 SOURCES += treebuilders.cpp importmusic.cpp directoryfinder.cpp … … 71 71 72 72 73 73 #The following line was inserted by qt3to4 74 QT += xml sql opengl qt3support 74 QT += xml sql opengl qt3support 75 75 76 76 include ( ../../libs-targetfix.pro ) -
mythplugins/mythmusic/mythmusic/aacdecoder.cpp
3 3 4 4 (c) 2003, 2004 Thor Sigvaldason and Isaac Richards 5 5 Part of the mythTV project 6 6 7 7 aac decoder methods 8 8 9 9 */ 10 10 11 11 #include <faad.h> … … 50 50 { 51 51 return the_decoder_object->aacRead((char *)buffer, length); 52 52 } 53 VERBOSE(VB_IMPORTANT, 53 VERBOSE(VB_IMPORTANT, 54 54 "read_callback called with no aacDecoder object assigned"); 55 55 return 0; 56 56 57 57 } 58 58 59 59 uint32_t seek_callback(void *user_data, uint64_t position) 60 60 { 61 61 aacDecoder *the_decoder_object = (aacDecoder*) user_data; … … 66 66 VERBOSE(VB_IMPORTANT, 67 67 "seek_callback called with no aacDecoder object assigned"); 68 68 return 0; 69 } 69 } 70 70 71 71 72 72 … … 76 76 77 77 78 78 79 aacDecoder::aacDecoder(const QString &file, DecoderFactory *d, QIODevice *i, 80 AudioOutput *o) 79 aacDecoder::aacDecoder(const QString &file, DecoderFactory *d, QIODevice *i, 80 AudioOutput *o) 81 81 : Decoder(d, i, o) 82 82 { 83 83 filename = file; … … 96 96 output_buf = 0; 97 97 output_bytes = 0; 98 98 output_at = 0; 99 99 100 100 mp4_file_flag = false; 101 101 mp4_callback = NULL; 102 102 timescale = 0; … … 124 124 { 125 125 ulong min = final ? 0 : bks; 126 126 127 while ((!done && !finish && seekTime <= 0) && output_bytes > min) 127 while ((!done && !finish && seekTime <= 0) && output_bytes > min) 128 128 { 129 if (user_stop || finish) 129 if (user_stop || finish) 130 130 { 131 131 inited = FALSE; 132 132 done = TRUE; 133 } 134 else 133 } 134 else 135 135 { 136 136 ulong sz = output_bytes < bks ? output_bytes : bks; 137 137 … … 147 147 lock(); 148 148 done = user_stop; 149 149 } 150 150 151 151 } 152 152 } 153 153 } … … 163 163 framesize = 0; 164 164 seekTime = -1.0; 165 165 totalTime = 0.0; 166 166 167 167 mp4_file_flag = false; 168 168 169 169 if (! input()) … … 172 172 return false; 173 173 } 174 174 175 175 176 176 if (!output_buf) { 177 177 output_buf = new char[globalBufferSize]; 178 178 } … … 198 198 error("couldn't seek in input"); 199 199 return false; 200 200 } 201 202 201 202 203 203 // 204 204 // figure out if it's an mp4 file (aac in a mp4 wrapper a la Apple) or 205 205 // just a pure aac file. 206 206 // 207 207 208 208 mp4_file_flag = false; 209 209 char header_buffer[8]; 210 210 input()->readBlock(header_buffer, 8); 211 211 212 212 // 213 213 // Seek back to the begining, otherwise the decoder gets totally confused. 214 214 // 215 215 216 216 input()->at(0); 217 217 218 218 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' && 222 222 header_buffer[7] == 'p' 223 223 ) 224 224 { 225 225 // 226 // It's an mp4/m4a (iTunes file) ... 226 // It's an mp4/m4a (iTunes file) ... 227 227 // 228 228 mp4_file_flag = true; 229 229 return initializeMP4(); … … 236 236 inited = false; 237 237 return false; 238 238 } 239 239 240 240 input()->close(); 241 241 inited = false; 242 242 return false; … … 253 253 mp4_callback->read = read_callback; 254 254 mp4_callback->seek = seek_callback; 255 255 mp4_callback->user_data = this; 256 256 257 257 // 258 258 // Open decoder library (?) 259 259 // 260 260 261 261 decoder_handle = faacDecOpen(); 262 262 263 263 // 264 264 // Set configuration 265 265 // 266 266 267 267 faacDecConfigurationPtr config = faacDecGetCurrentConfiguration(decoder_handle); 268 268 config->outputFormat = FAAD_FMT_16BIT; 269 269 config->downMatrix = 0; // if 1, we could downmix 5.1 to 2 ... apparently 270 270 config->dontUpSampleImplicitSBR = 1; 271 271 faacDecSetConfiguration(decoder_handle, config); 272 272 273 273 // 274 // Open the mp4 input file 275 // 274 // Open the mp4 input file 275 // 276 276 277 277 mp4_input_file = mp4ff_open_read(mp4_callback); 278 278 if (!mp4_input_file) … … 305 305 uint buffer_size; 306 306 307 307 mp4ff_get_decoder_config( 308 mp4_input_file, 309 aac_track_number, 310 &buffer, 308 mp4_input_file, 309 aac_track_number, 310 &buffer, 311 311 &buffer_size 312 312 ); 313 313 // some linux distros (gentoo, debian) modify the faad2 api with stdint.h types … … 335 335 336 336 timescale = mp4ff_time_scale(mp4_input_file, aac_track_number); 337 337 framesize = 1024; 338 338 339 339 // 340 340 // Fiddle with the default frame size if the data appears to need it 341 // 341 // 342 342 343 343 mp4AudioSpecificConfig mp4ASC; 344 344 if (buffer) … … 354 354 // 355 355 // Extract some information about the content 356 356 // 357 357 358 358 long samples = mp4ff_num_samples(mp4_input_file, aac_track_number); 359 359 float f = 1024.0; 360 360 float seconds; 361 361 362 362 if (mp4ASC.sbr_present_flag == 1) 363 363 { 364 364 f = f * 2.0; 365 365 } 366 366 367 367 seconds = (float)samples*(float)(f-1.0)/(float)mp4ASC.samplingFrequency; 368 368 369 369 totalTime = seconds; … … 374 374 { 375 375 bitrate = mp4ff_get_avg_bitrate(mp4_input_file, aac_track_number) / 1000; 376 376 } 377 377 378 378 // 379 379 // Check we got same answers from mp4ASC 380 380 // … … 437 437 438 438 // 439 439 // No AAC tracks 440 // 440 // 441 441 return -1; 442 442 } 443 443 … … 470 470 471 471 lock(); 472 472 473 if (!inited) 473 if (!inited) 474 474 { 475 475 error("aacDecoder: run() called without being init'd"); 476 476 unlock(); … … 496 496 uchar *buffer; 497 497 uint buffer_size; 498 498 499 while (!done && !finish && !user_stop) 499 while (!done && !finish && !user_stop) 500 500 { 501 501 lock(); 502 502 503 503 ++current_sample; 504 if (seekTime >= 0.0) 504 if (seekTime >= 0.0) 505 505 { 506 506 // 507 507 // Crap ... seek ... well, this is approximately correct 508 // 508 // 509 509 510 510 current_sample = (long int) (((double)(seekTime / totalTime)) * total_numb_samples); 511 511 seekTime = -1.0; 512 512 } 513 513 514 514 if (current_sample >= total_numb_samples) 515 515 { 516 516 // 517 517 // We're done ... make sure we play all the remaining output 518 518 // 519 519 520 520 flush(TRUE); 521 521 522 522 if (output()) … … 539 539 buffer_size = 0; 540 540 541 541 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, 546 546 &buffer_size 547 547 ); 548 548 if (rc == 0) … … 552 552 } 553 553 else 554 554 { 555 555 556 556 faacDecFrameInfo frame_info; 557 557 void *sample_buffer = faacDecDecode( 558 decoder_handle, 559 &frame_info, 560 buffer, 558 decoder_handle, 559 &frame_info, 560 buffer, 561 561 buffer_size 562 562 ); 563 563 564 564 sample_count = frame_info.samples; 565 565 566 566 // … … 568 568 // to the output (after checking we're not going to exceed 569 569 // the output buffer size) 570 570 // 571 571 572 572 if (((sample_count * 2) + output_at ) >= globalBufferSize) 573 573 { 574 574 error("aacDecoder: gloablBufferSize too small, " … … 576 576 "sound like crap)"); 577 577 sample_count = ((globalBufferSize - output_at) / 2) - 100; 578 578 } 579 579 580 580 char *char_buffer = (char *)sample_buffer; 581 581 short *sample_buffer16 = (short*)char_buffer; 582 582 for(uint i = 0; i < sample_count; i++) … … 584 584 output_buf[output_at + (i*2)] = (char)(sample_buffer16[i] & 0xFF); 585 585 output_buf[output_at + (i*2) + 1] = (char)((sample_buffer16[i] >> 8) & 0xFF); 586 586 } 587 587 588 588 if (sample_count > 0) 589 589 { 590 590 output_at += sample_count * 2; … … 595 595 if (bitrate) 596 596 { 597 597 output()->SetSourceBitrate(bitrate); 598 } 599 else 598 } 599 else 600 600 { 601 601 output()->SetSourceBitrate( 602 602 (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) 605 605 * frame_info.samplerate) / 1000); 606 606 } 607 607 608 608 flush(); 609 609 } 610 610 } 611 611 612 612 if (buffer) 613 613 { 614 614 free(buffer); … … 656 656 { 657 657 return 0; 658 658 } 659 return read_result; 659 return read_result; 660 660 } 661 661 error("aacDecoder: aacRead() was called, but there is no input"); 662 662 return 0; … … 691 691 692 692 const QString &aacDecoderFactory::extension() const 693 693 { 694 static QString ext(". m4a");694 static QString ext(".aac|.m4a"); 695 695 return ext; 696 696 } 697 697 … … 702 702 return desc; 703 703 } 704 704 705 Decoder *aacDecoderFactory::create(const QString &file, QIODevice *input, 705 Decoder *aacDecoderFactory::create(const QString &file, QIODevice *input, 706 706 AudioOutput *output, bool deletable) 707 707 { 708 708 … … 710 710 return new aacDecoder(file, this, input, output); 711 711 712 712 static aacDecoder *decoder = 0; 713 if (!decoder) 713 if (!decoder) 714 714 { 715 715 decoder = new aacDecoder(file, this, input, output); 716 } 717 else 716 } 717 else 718 718 { 719 719 decoder->setInput(input); 720 720 decoder->setOutput(output); -
mythplugins/mythmusic/mythmusic/decoder.h
89 89 static QStringList all(); 90 90 static bool supports(const QString &); 91 91 static void registerFactory(DecoderFactory *); 92 static Decoder *create(const QString &, QIODevice *, AudioOutput *, 92 static Decoder *create(const QString &, QIODevice *, AudioOutput *, 93 93 bool = FALSE); 94 94 static void SetLocationFormatUseTags(void); 95 95 … … 126 126 virtual ~DecoderFactory() {} 127 127 }; 128 128 129 class VorbisDecoderFactory : public DecoderFactory130 {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 DecoderFactory139 {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 147 129 class CdDecoderFactory : public DecoderFactory 148 130 { 149 131 public: … … 153 135 Decoder *create(const QString &, QIODevice *, AudioOutput *, bool); 154 136 }; 155 137 156 class FlacDecoderFactory : public DecoderFactory157 {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 165 138 class avfDecoderFactory : public DecoderFactory 166 139 { 167 140 public: -
mythplugins/mythmusic/mythmusic/decoder.cpp
20 20 21 21 #include <mythtv/mythcontext.h> 22 22 23 DecoderEvent* DecoderEvent::clone() 24 { 23 DecoderEvent* DecoderEvent::clone() 24 { 25 25 DecoderEvent *result = new DecoderEvent(*this); 26 26 27 27 if (error_msg) … … 57 57 unlock(); 58 58 } 59 59 60 void Decoder::error(const QString &e) 60 void Decoder::error(const QString &e) 61 61 { 62 62 QString *str = new QString(e.toUtf8()); 63 63 DecoderEvent ev(str); … … 98 98 99 99 100 100 /** \fn Decoder::getMetadata(void) 101 * \brief Get the metadata for \p filename 101 * \brief Get the metadata for \p filename 102 102 * 103 103 * First tries to read the metadata from the database. If there 104 104 * is no database entry, it'll call \p Decoder::readMetadata. … … 127 127 * instance of the appropriate MetaIO subtype. It is used by \p 128 128 * Decoder::getMetadata, \p Decoder::readMetadata and \p 129 129 * Decoder::commitMetadata. 130 * 130 * 131 131 * The default implementation returns a NULL pointer, which 132 132 * essentially means, that if the decoder does not overrider this 133 133 * method or all of the users (see previous paragraph), files … … 182 182 183 183 static Q3PtrList<DecoderFactory> *factories = 0; 184 184 185 static void checkFactories() 185 static void checkFactories() 186 186 { 187 if (!factories) 187 if (!factories) 188 188 { 189 189 factories = new Q3PtrList<DecoderFactory>; 190 190 191 Decoder::registerFactory(new VorbisDecoderFactory);192 Decoder::registerFactory(new MadDecoderFactory);193 Decoder::registerFactory(new FlacDecoderFactory);194 191 #ifndef USING_MINGW 195 192 Decoder::registerFactory(new CdDecoderFactory); 196 193 #endif // USING_MINGW … … 207 204 208 205 QStringList l; 209 206 DecoderFactory *fact = factories->first(); 210 while (fact) 207 while (fact) 211 208 { 212 209 l << fact->description(); 213 210 fact = factories->next(); … … 221 218 checkFactories(); 222 219 223 220 DecoderFactory *fact = factories->first(); 224 while (fact) 221 while (fact) 225 222 { 226 223 if (fact->supports(source)) 227 224 return TRUE; … … 245 242 Decoder *decoder = 0; 246 243 247 244 DecoderFactory *fact = factories->first(); 248 while (fact) 245 while (fact) 249 246 { 250 if (fact->supports(source)) 247 if (fact->supports(source)) 251 248 { 252 249 decoder = fact->create(source, input, output, deletable); 253 250 break; -
mythplugins/mythmusic/mythmusic/avfdecoder.cpp
2 2 MythTV WMA Decoder 3 3 Written by Kevin Kuphal 4 4 5 Special thanks to 5 Special thanks to 6 6 ffmpeg team for libavcodec and libavformat 7 7 qemacs team for their av support which I used to understand the libraries 8 8 getid3.sourceforget.net project for the ASF information used here 9 10 This library decodes Windows Media (WMA/ASF) files into PCM data11 returned to the MythMusic output buffer.12 9 10 This library decodes Windows Media (WMA/ASF) files into PCM data 11 returned to the MythMusic output buffer. 12 13 13 Revision History 14 14 - Initial release 15 15 - 1/9/2004 - Improved seek support 16 16 */ 17 17 18 // C++ headers 18 19 #include <iostream> 19 20 #include <string> 20 #include <qobject.h>21 #include <qiodevice.h>22 #include <qfile.h>23 21 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 24 32 using namespace std; 25 33 34 // Mythmusic Headers 26 35 #include "avfdecoder.h" 27 36 #include "constants.h" 28 #include <mythtv/audiooutput.h>29 37 #include "metadata.h" 30 38 #include "metaioavfcomment.h" 31 39 32 #include <mythtv/mythcontext.h>33 40 34 avfDecoder::avfDecoder(const QString &file, DecoderFactory *d, QIODevice *i, 35 AudioOutput *o) 41 avfDecoder::avfDecoder(const QString &file, DecoderFactory *d, QIODevice *i, 42 AudioOutput *o) 36 43 : Decoder(d, i, o) 37 44 { 38 45 filename = file; … … 47 54 bitrate = 0; 48 55 seekTime = -1.0; 49 56 totalTime = 0.0; 50 chan= 0;57 m_channels = 0; 51 58 output_buf = 0; 52 59 output_bytes = 0; 53 60 output_at = 0; 54 61 55 ic = NULL; 56 oc = NULL; 57 ifmt = NULL; 58 ap = ¶ms; 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; 60 69 } 61 70 62 71 avfDecoder::~avfDecoder(void) … … 80 89 { 81 90 ulong min = final ? 0 : bks; 82 91 83 while ((!done && !finish && seekTime <= 0) && output_bytes > min) 92 while ((!done && !finish && seekTime <= 0) && output_bytes > min) 84 93 { 85 if (user_stop || finish) 94 if (user_stop || finish) 86 95 { 87 96 inited = FALSE; 88 97 done = TRUE; 89 } 90 else 98 } 99 else 91 100 { 92 101 ulong sz = output_bytes < bks ? output_bytes : bks; 93 102 94 int samples = (sz*8)/( chan*16);103 int samples = (sz*8)/(m_channels*16); 95 104 if (output()->AddSamples(output_buf, samples, -1)) 96 105 { 97 106 output_bytes -= sz; … … 109 118 110 119 bool avfDecoder::initialize() 111 120 { 121 VERBOSE(VB_GENERAL, "Initialising"); 112 122 bks = blockSize(); 113 123 114 124 inited = user_stop = done = finish = FALSE; 115 125 len = freq = bitrate = 0; 116 stat = chan= 0;126 stat = m_channels = 0; 117 127 seekTime = -1.0; 118 128 totalTime = 0.0; 119 129 120 130 filename = ((QFile *)input())->name(); 121 131 122 132 if (!output_buf) 123 133 output_buf = new char[globalBufferSize]; 124 134 output_at = 0; … … 130 140 131 141 // open the media file 132 142 // 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 } 135 148 136 149 // determine the stream format 137 150 // 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(); 139 154 return FALSE; 155 } 140 156 141 157 // Store the audio codec of the stream 142 audio_dec = ic->streams[0]->codec;158 m_audioDec = m_inputContext->streams[0]->codec; 143 159 144 160 // Store the input format of the context 145 ifmt = ic->iformat;161 m_inputFormat = m_inputContext->iformat; 146 162 147 163 // Determine the output format 148 164 // Given we are outputing to a sound card, this will always 149 165 // be a PCM format 166 150 167 #ifdef WORDS_BIGENDIAN 151 fmt = guess_format("s16be", NULL, NULL);168 m_outputFormat = guess_format("s16be", NULL, NULL); 152 169 #else 153 fmt = guess_format("s16le", NULL, NULL);170 m_outputFormat = guess_format("s16le", NULL, NULL); 154 171 #endif 155 if (!fmt) 172 173 if (!m_outputFormat) 156 174 { 157 175 VERBOSE(VB_IMPORTANT, "avfDecoder.o - failed to get output format"); 176 deinit(); 158 177 return FALSE; 159 178 } 160 179 161 180 // Populate the output context 162 181 // Create the output stream and attach to output context 163 182 // 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; 166 185 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); 174 193 175 194 // Prepare the decoding codec 176 195 // The format is different than the codec 177 196 // While we could get fed a WAV file, it could contain a number 178 197 // 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(); 181 202 return FALSE; 182 if (avcodec_open(audio_dec,codec) < 0) 203 } 204 if (avcodec_open(m_audioDec,m_codec) < 0) 205 { 206 deinit(); 183 207 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; 185 211 186 freq = audio_dec->sample_rate;187 chan = audio_dec->channels;212 freq = m_audioDec->sample_rate; 213 m_channels = m_audioDec->channels; 188 214 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 189 224 if (output()) 190 225 { 191 226 const AudioSettings settings( 192 16 /*bits*/, audio_dec->channels, audio_dec->sample_rate,227 16 /*bits*/, m_audioDec->channels, m_audioDec->sample_rate, 193 228 false /* AC3/DTS pass through */); 194 229 output()->Reconfigure(settings); 195 output()->SetSourceBitrate( audio_dec->bit_rate);230 output()->SetSourceBitrate(m_audioDec->bit_rate); 196 231 } 197 232 198 233 inited = TRUE; … … 206 241 207 242 void avfDecoder::deinit() 208 243 { 244 VERBOSE(VB_GENERAL, "De-initialising"); 209 245 inited = user_stop = done = finish = FALSE; 210 246 len = freq = bitrate = 0; 211 stat = chan= 0;247 stat = m_channels = 0; 212 248 setInput(0); 213 249 setOutput(0); 214 250 215 251 // Cleanup here 216 if( ic)252 if(m_inputContext) 217 253 { 218 av_close_input_file( ic);219 ic= NULL;254 av_close_input_file(m_inputContext); 255 m_inputContext = NULL; 220 256 } 221 if( oc)257 if(m_outputContext) 222 258 { 223 av_free( oc);224 oc= NULL;259 av_free(m_outputContext); 260 m_outputContext = NULL; 225 261 } 262 263 m_decStream = NULL; 264 m_codec = NULL; 265 m_audioEnc = m_audioDec = NULL; 266 m_inputFormat = NULL; 267 m_outputFormat = NULL; 226 268 } 227 269 228 270 void avfDecoder::run() … … 232 274 233 275 lock(); 234 276 235 if (!inited) 277 if (!inited) 236 278 { 237 279 unlock(); 238 280 return; … … 247 289 dispatch(e); 248 290 } 249 291 250 av_read_play( ic);251 while (!done && !finish && !user_stop) 292 av_read_play(m_inputContext); 293 while (!done && !finish && !user_stop) 252 294 { 253 295 lock(); 254 296 255 297 // Look to see if user has requested a seek 256 if (seekTime >= 0.0) 298 if (seekTime >= 0.0) 257 299 { 258 300 VERBOSE(VB_GENERAL, QString("avfdecoder.o: seek time %1") 259 301 .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) 261 303 < 0) 262 304 { 263 305 VERBOSE(VB_IMPORTANT, "Error seeking"); … … 267 309 } 268 310 269 311 // 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) 272 314 { 273 315 VERBOSE(VB_IMPORTANT, "Read frame failed"); 274 316 unlock(); … … 277 319 } 278 320 279 321 // 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; 282 324 unlock(); 283 325 284 while (len > 0 && !done && !finish && !user_stop && seekTime <= 0.0) 326 while (len > 0 && !done && !finish && !user_stop && seekTime <= 0.0) 285 327 { 286 328 lock(); 287 329 // Decode the stream to the output codec … … 289 331 // data_size is the size in bytes of the frame 290 332 // ptr is the input buffer 291 333 // 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) 295 337 { 296 338 unlock(); 297 339 break; … … 300 342 s = (char *)samples; 301 343 unlock(); 302 344 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) 305 347 { 306 348 lock(); 307 349 // Store and check the size … … 339 381 len -= dec_len; 340 382 unlock(); 341 383 } 342 av_free_packet( pkt);384 av_free_packet(m_pkt); 343 385 } 344 386 345 387 flush(TRUE); 346 if (output()) 388 389 if (output() && !user_stop) 347 390 output()->Drain(); 348 391 349 392 if (finish) … … 364 407 MetaIO* avfDecoder::doCreateTagger(void) 365 408 { 366 409 return new MetaIOAVFComment(); 367 } 410 } 368 411 369 412 bool avfDecoderFactory::supports(const QString &source) const 370 413 { … … 380 423 381 424 const QString &avfDecoderFactory::extension() const 382 425 { 383 static QString ext(".wma|.wav"); 426 static QString ext(".mp3|.mp2|.ogg|.flac|.wma|.wav|.ac3|.oma|.omg|.atp|" 427 ".ra|.dts"); 384 428 return ext; 385 429 } 386 430 … … 390 434 return desc; 391 435 } 392 436 393 Decoder *avfDecoderFactory::create(const QString &file, QIODevice *input, 437 Decoder *avfDecoderFactory::create(const QString &file, QIODevice *input, 394 438 AudioOutput *output, bool deletable) 395 439 { 396 440 if (deletable) 397 441 return new avfDecoder(file, this, input, output); 398 442 399 443 static avfDecoder *decoder = 0; 400 if (!decoder) 444 if (!decoder) 401 445 { 402 446 decoder = new avfDecoder(file, this, input, output); 403 } 404 else 447 } 448 else 405 449 { 406 450 decoder->setInput(input); 407 451 decoder->setOutput(output); -
mythplugins/mythmusic/mythmusic/main.cpp
23 23 // MythMusic headers 24 24 #include "decoder.h" 25 25 #include "metadata.h" 26 #include "maddecoder.h"27 #include "vorbisdecoder.h"28 26 #include "databasebox.h" 29 27 #include "playbackbox.h" 30 28 #include "playlist.h" -
mythplugins/mythmusic/mythmusic/avfdecoder.h
37 37 unsigned int bks; 38 38 bool done, finish; 39 39 long len, freq, bitrate; 40 int chan;40 int m_channels; 41 41 unsigned long output_size; 42 42 double totalTime, seekTime; 43 43 … … 46 46 long int start; 47 47 long int end; 48 48 49 AVOutputFormat * fmt;// Encoding format (PCM)50 AVInputFormat * ifmt;// Decoding format51 AVFormatParameters params;52 AVFormatParameters * ap;53 AVFormatContext * oc, *ic;54 AVStream * enc_st, *dec_st;55 AVCodec * codec, *enc_codec;// Codec56 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; 59 59 60 60 int errcode; 61 61 -
mythplugins/mythmusic/mythmusic/filescanner.cpp
16 16 17 17 // MythMusic headers 18 18 #include "decoder.h" 19 #include "maddecoder.h"20 #include "vorbisdecoder.h"21 19 #include "filescanner.h" 22 20 #include "metadata.h" 23 21