Ticket #1104: mythtv_ac3.25.patch
File mythtv_ac3.25.patch, 66.8 KB (added by , 18 years ago) |
---|
-
libs/libmyth/libmyth.pro
35 35 SOURCES += virtualkeyboard.cpp mythobservable.cpp mythsocket.cpp 36 36 37 37 INCLUDEPATH += ../libmythsamplerate ../libmythsoundtouch ../.. ../ 38 INCLUDEPATH += ../libavutil 38 39 DEPENDPATH += ../libmythsamplerate ../libmythsoundtouch ../ ../libmythui 40 DEPENDPATH += ../libavutil ../libavcodec 39 41 40 42 LIBS += -L../libmythsamplerate -lmythsamplerate-$${LIBVERSION} 41 43 LIBS += -L../libmythsoundtouch -lmythsoundtouch-$${LIBVERSION} 44 LIBS += -L../libavcodec -lmythavcodec-$${LIBVERSION} 45 LIBS += -la52 42 46 43 47 isEmpty(QMAKE_EXTENSION_SHLIB) { 44 48 QMAKE_EXTENSION_SHLIB=so -
libs/libmyth/audiooutput.h
31 31 virtual ~AudioOutput() { }; 32 32 33 33 // reconfigure sound out for new params 34 virtual void Reconfigure(int audio_bits, int audio_channels, 35 int audio_samplerate, bool audio_passthru) = 0; 34 virtual void Reconfigure(int audio_bits, 35 int audio_channels, 36 int audio_samplerate, 37 bool audio_passthru, 38 void* audio_codec = NULL 39 ) = 0; 36 40 37 41 virtual void SetStretchFactor(float factor); 38 42 … … 74 78 lastError = msg; 75 79 VERBOSE(VB_IMPORTANT, "AudioOutput Error: " + lastError); 76 80 } 81 void ClearError() 82 { lastError = QString::null; }; 77 83 78 84 void Warn(QString msg) 79 85 { -
libs/libmyth/audiooutputdx.h
35 35 /// END HACK HACK HACK HACK 36 36 37 37 virtual void Reset(void); 38 virtual void Reconfigure(int audio_bits, int audio_channels, 39 int audio_samplerate, int audio_passthru); 38 virtual void Reconfigure(int audio_bits, 39 int audio_channels, 40 int audio_samplerate, 41 bool audio_passthru, 42 AudioCodecMode aom = AUDIOCODECMODE_NORMAL); 40 43 virtual void SetBlocking(bool blocking); 41 44 42 45 virtual bool AddSamples(char *buffer, int samples, long long timecode); -
libs/libmyth/audiooutputdx.cpp
130 130 // FIXME: kedl: not sure what else could be required here? 131 131 } 132 132 133 void AudioOutputDX::Reconfigure(int audio_bits, int audio_channels, 134 int audio_samplerate, int audio_passthru) 133 void AudioOutputDX::Reconfigure(int audio_bits, 134 int audio_channels, 135 int audio_samplerate, 136 int audio_passthru, 137 AudioCodecMode laom 138 ) 135 139 { 136 140 if (dsbuffer) 137 141 DestroyDSBuffer(); -
libs/libmyth/audiooutputbase.h
18 18 #include "samplerate.h" 19 19 #include "SoundTouch.h" 20 20 21 #define AUDBUFSIZE 768000 21 struct AVCodecContext; 22 class DigitalEncoder; 22 23 #define AUDIO_SRC_IN_SIZE 16384 23 24 #define AUDIO_SRC_OUT_SIZE (16384*6) 24 25 #define AUDIO_TMP_BUF_SIZE (16384*6) 25 26 27 //#define AUDBUFSIZE 768000 28 //divisible by 12,10,8,6,4,2 and around 1024000 29 //#define AUDBUFSIZE 1024080 30 #define AUDBUFSIZE 1536000 31 26 32 class AudioOutputBase : public AudioOutput 27 33 { 28 34 public: … … 35 41 virtual ~AudioOutputBase(); 36 42 37 43 // reconfigure sound out for new params 38 virtual void Reconfigure(int audio_bits, int audio_channels, 39 int audio_samplerate, bool audio_passthru); 44 virtual void Reconfigure(int audio_bits, 45 int audio_channels, 46 int audio_samplerate, 47 bool audio_passthru, 48 void* audio_codec = NULL); 40 49 41 50 // do AddSamples calls block? 42 51 virtual void SetBlocking(bool blocking); … … 125 134 bool audio_passthru; 126 135 127 136 float audio_stretchfactor; 137 AVCodecContext *audio_codec; 128 138 AudioOutputSource source; 129 139 130 140 bool killaudio; … … 133 143 bool set_initial_vol; 134 144 bool buffer_output_data_for_use; // used by AudioOutputNULL 135 145 146 int configured_audio_channels; 147 136 148 private: 137 149 // resampler 138 150 bool need_resampler; … … 144 156 145 157 // timestretch 146 158 soundtouch::SoundTouch * pSoundStretch; 159 DigitalEncoder * encoder; 147 160 148 161 bool blocking; // do AddSamples calls block? 149 162 … … 160 173 161 174 pthread_mutex_t avsync_lock; /* must hold avsync_lock to read or write 162 175 'audiotime' and 'audiotime_updated' */ 163 intaudiotime; // timecode of audio leaving the soundcard (same units as176 long long audiotime; // timecode of audio leaving the soundcard (same units as 164 177 // timecodes) ... 165 178 struct timeval audiotime_updated; // ... which was last updated at this time 166 179 167 180 /* Audio circular buffer */ 168 181 unsigned char audiobuffer[AUDBUFSIZE]; /* buffer */ 169 182 int raud, waud; /* read and write positions */ 170 intaudbuf_timecode; /* timecode of audio most recently placed into183 long long audbuf_timecode; /* timecode of audio most recently placed into 171 184 buffer */ 172 185 173 186 int numlowbuffer; -
libs/libmyth/audiooutputbase.cpp
16 16 // MythTV headers 17 17 #include "audiooutputbase.h" 18 18 19 extern "C" { 20 #include "libavcodec/avcodec.h" 21 //#include "libavcodec/liba52/a52.h" 22 #include <a52dec/a52.h> 23 } 24 25 #if QT_VERSION < 0x030200 26 #define LONGLONGCONVERT (long) 27 #else 28 #define LONGLONGCONVERT 29 #endif 30 31 #define LOC QString("DEnc: "); 32 #define MAX_AC3_FRAME_SIZE 6144 33 class DigitalEncoder 34 { 35 public: 36 DigitalEncoder(); 37 ~DigitalEncoder(); 38 void Dispose(); 39 bool Init(CodecID codec_id, int bitrate, int samplerate, int channels); 40 size_t Encode(short * buff); 41 42 // if needed 43 char * GetFrameBuffer() 44 { 45 if (!frame_buffer && av_context) 46 { 47 frame_buffer = new char [one_frame_bytes]; 48 } 49 return frame_buffer; 50 } 51 size_t FrameSize() const { return one_frame_bytes; } 52 char * GetOutBuff() const { return outbuf; } 53 54 size_t audio_bytes_per_sample; 55 private: 56 AVCodecContext *av_context; 57 char * outbuf; 58 char * frame_buffer; 59 int outbuf_size; 60 size_t one_frame_bytes; 61 }; 62 63 DigitalEncoder::DigitalEncoder() 64 { 65 av_context = NULL; 66 outbuf = NULL; 67 outbuf_size = 0; 68 one_frame_bytes = 0; 69 frame_buffer = NULL; 70 } 71 72 DigitalEncoder::~DigitalEncoder() 73 { 74 Dispose(); 75 } 76 77 void DigitalEncoder::Dispose() 78 { 79 if (av_context) 80 { 81 avcodec_close(av_context); 82 av_free(av_context); 83 av_context = NULL; 84 } 85 if (outbuf) 86 { 87 delete [] outbuf; 88 outbuf = NULL; 89 outbuf_size = 0; 90 } 91 if (frame_buffer) 92 { 93 delete [] frame_buffer; 94 frame_buffer = NULL; 95 one_frame_bytes = 0; 96 } 97 } 98 99 //CODEC_ID_AC3 100 bool DigitalEncoder::Init(CodecID codec_id, int bitrate, int samplerate, int channels) 101 { 102 AVCodec * codec; 103 int ret; 104 105 VERBOSE(VB_AUDIO, QString("DigitalEncoder::Init codecid=%1, br=%2, sr=%3, ch=%4") 106 .arg(codec_id_string(codec_id)) 107 .arg(bitrate) 108 .arg(samplerate) 109 .arg(channels)); 110 //codec = avcodec_find_encoder(codec_id); 111 // always AC3 as there is no DTS encoder at the moment 2005/1/9 112 codec = avcodec_find_encoder(CODEC_ID_AC3); 113 if (!codec) 114 { 115 VERBOSE(VB_IMPORTANT,"Error: could not find codec"); 116 return false; 117 } 118 av_context = avcodec_alloc_context(); 119 av_context->bit_rate = bitrate; 120 av_context->sample_rate = samplerate; 121 av_context->channels = channels; 122 // open it */ 123 if ((ret = avcodec_open(av_context, codec)) < 0) 124 { 125 VERBOSE(VB_IMPORTANT,"Error: could not open codec, invalid bitrate or samplerate"); 126 Dispose(); 127 return false; 128 } 129 130 size_t bytes_per_frame = av_context->channels * sizeof(short); 131 audio_bytes_per_sample = bytes_per_frame; 132 one_frame_bytes = bytes_per_frame * av_context->frame_size; 133 134 outbuf_size = 16384; // ok for AC3 but DTS? 135 outbuf = new char [outbuf_size]; 136 VERBOSE(VB_AUDIO, QString("DigitalEncoder::Init fs=%1, bpf=%2 ofb=%3") 137 .arg(av_context->frame_size) 138 .arg(bytes_per_frame) 139 .arg(one_frame_bytes) 140 ); 141 142 return true; 143 } 144 145 static int DTS_SAMPLEFREQS[16] = 146 { 147 0, 8000, 16000, 32000, 64000, 128000, 11025, 22050, 148 44100, 88200, 176400, 12000, 24000, 48000, 96000, 192000 149 }; 150 151 static int DTS_BITRATES[30] = 152 { 153 32000, 56000, 64000, 96000, 112000, 128000, 154 192000, 224000, 256000, 320000, 384000, 448000, 155 512000, 576000, 640000, 768000, 896000, 1024000, 156 1152000, 1280000, 1344000, 1408000, 1411200, 1472000, 157 1536000, 1920000, 2048000, 3072000, 3840000, 4096000 158 }; 159 160 static int dts_decode_header(uint8_t *indata_ptr, int *rate, 161 int *nblks, int *sfreq) 162 { 163 uint id = ((indata_ptr[0] << 24) | (indata_ptr[1] << 16) | 164 (indata_ptr[2] << 8) | (indata_ptr[3])); 165 166 if (id != 0x7ffe8001) 167 return -1; 168 169 int ftype = indata_ptr[4] >> 7; 170 171 int surp = (indata_ptr[4] >> 2) & 0x1f; 172 surp = (surp + 1) % 32; 173 174 *nblks = (indata_ptr[4] & 0x01) << 6 | (indata_ptr[5] >> 2); 175 ++*nblks; 176 177 int fsize = (indata_ptr[5] & 0x03) << 12 | 178 (indata_ptr[6] << 4) | (indata_ptr[7] >> 4); 179 ++fsize; 180 181 *sfreq = (indata_ptr[8] >> 2) & 0x0f; 182 *rate = (indata_ptr[8] & 0x03) << 3 | ((indata_ptr[9] >> 5) & 0x07); 183 184 if (ftype != 1) 185 { 186 VERBOSE(VB_IMPORTANT, LOC + 187 QString("DTS: Termination frames not handled (ftype %1)") 188 .arg(ftype)); 189 return -1; 190 } 191 192 if (*sfreq != 13) 193 { 194 VERBOSE(VB_IMPORTANT, LOC + 195 QString("DTS: Only 48kHz supported (sfreq %1)").arg(*sfreq)); 196 return -1; 197 } 198 199 if ((fsize > 8192) || (fsize < 96)) 200 { 201 VERBOSE(VB_IMPORTANT, LOC + 202 QString("DTS: fsize: %1 invalid").arg(fsize)); 203 return -1; 204 } 205 206 if (*nblks != 8 && *nblks != 16 && *nblks != 32 && 207 *nblks != 64 && *nblks != 128 && ftype == 1) 208 { 209 VERBOSE(VB_IMPORTANT, LOC + 210 QString("DTS: nblks %1 not valid for normal frame") 211 .arg(*nblks)); 212 return -1; 213 } 214 215 return fsize; 216 } 217 218 static int dts_syncinfo(uint8_t *indata_ptr, int * /*flags*/, 219 int *sample_rate, int *bit_rate) 220 { 221 int nblks; 222 int rate; 223 int sfreq; 224 225 int fsize = dts_decode_header(indata_ptr, &rate, &nblks, &sfreq); 226 if (fsize >= 0) 227 { 228 if (rate >= 0 && rate <= 29) 229 *bit_rate = DTS_BITRATES[rate]; 230 else 231 *bit_rate = 0; 232 if (sfreq >= 1 && sfreq <= 15) 233 *sample_rate = DTS_SAMPLEFREQS[sfreq]; 234 else 235 *sample_rate = 0; 236 } 237 return fsize; 238 } 239 240 static int encode_frame( 241 bool dts, 242 unsigned char *data, 243 size_t &len) 244 { 245 size_t enc_len; 246 int flags, sample_rate, bit_rate; 247 248 // we don't do any length/crc validation of the AC3 frame here; presumably 249 // the receiver will have enough sense to do that. if someone has a 250 // receiver that doesn't, here would be a good place to put in a call 251 // to a52_crc16_block(samples+2, data_size-2) - but what do we do if the 252 // packet is bad? we'd need to send something that the receiver would 253 // ignore, and if so, may as well just assume that it will ignore 254 // anything with a bad CRC... 255 256 uint nr_samples = 0, block_len; 257 if (dts) 258 { 259 enc_len = dts_syncinfo(data+8, &flags, &sample_rate, &bit_rate); 260 int rate, sfreq, nblks; 261 dts_decode_header(data+8, &rate, &nblks, &sfreq); 262 nr_samples = nblks * 32; 263 block_len = nr_samples * 2 * 2; 264 } 265 else 266 { 267 enc_len = a52_syncinfo(data+8, &flags, &sample_rate, &bit_rate); 268 block_len = MAX_AC3_FRAME_SIZE; 269 } 270 271 if (enc_len == 0 || enc_len > len) 272 { 273 int l = len; 274 len = 0; 275 return l; 276 } 277 278 enc_len = min((uint)enc_len, block_len - 8); 279 280 //uint32_t x = *(uint32_t*)(data+8); 281 // in place swab 282 swab(data+8, data+8, enc_len); 283 //VERBOSE(VB_AUDIO|VB_TIMESTAMP, 284 // QString("DigitalEncoder::Encode swab test %1 %2") 285 // .arg(x,0,16).arg(*(uint32_t*)(data+8),0,16)); 286 287 // the following values come from libmpcodecs/ad_hwac3.c in mplayer. 288 // they form a valid IEC958 AC3 header. 289 data[0] = 0x72; 290 data[1] = 0xF8; 291 data[2] = 0x1F; 292 data[3] = 0x4E; 293 data[4] = 0x01; 294 if (dts) 295 { 296 switch(nr_samples) 297 { 298 case 512: 299 data[4] = 0x0B; /* DTS-1 (512-sample bursts) */ 300 break; 301 302 case 1024: 303 data[4] = 0x0C; /* DTS-2 (1024-sample bursts) */ 304 break; 305 306 case 2048: 307 data[4] = 0x0D; /* DTS-3 (2048-sample bursts) */ 308 break; 309 310 default: 311 VERBOSE(VB_IMPORTANT, LOC + 312 QString("DTS: %1-sample bursts not supported") 313 .arg(nr_samples)); 314 data[4] = 0x00; 315 break; 316 } 317 } 318 data[5] = 0x00; 319 data[6] = (enc_len << 3) & 0xFF; 320 data[7] = (enc_len >> 5) & 0xFF; 321 memset(data + 8 + enc_len, 0, block_len - 8 - enc_len); 322 len = block_len; 323 324 return enc_len; 325 } 326 327 // must have exactly 1 frames worth of data 328 size_t DigitalEncoder::Encode(short * buff) 329 { 330 int encsize = 0; 331 size_t outsize = 0; 332 333 // put data in the correct spot for encode frame 334 outsize = avcodec_encode_audio( 335 av_context, 336 ((uchar*)outbuf)+8, 337 outbuf_size-8, 338 buff); 339 size_t tmpsize = outsize; 340 341 outsize = MAX_AC3_FRAME_SIZE; 342 encsize = encode_frame( 343 //av_context->codec_id==CODEC_ID_DTS, 344 false, 345 (unsigned char*)outbuf, outsize); 346 VERBOSE(VB_AUDIO|VB_TIMESTAMP, 347 QString("DigitalEncoder::Encode len1=%1 len2=%2 finallen=%3") 348 .arg(tmpsize) 349 .arg(encsize) 350 .arg(outsize) 351 ); 352 353 return outsize; 354 } 355 #undef LOC 19 356 #define LOC QString("AO: ") 20 357 #define LOC_ERR QString("AO, ERROR: ") 21 358 … … 24 361 int /*laudio_bits*/, int /*laudio_channels*/, 25 362 int /*laudio_samplerate*/, AudioOutputSource lsource, 26 363 bool lset_initial_vol, bool /*laudio_passthru*/) : 27 28 364 effdsp(0), effdspstretched(0), 29 365 audio_channels(-1), audio_bytes_per_sample(0), 30 366 audio_bits(-1), audio_samplerate(-1), … … 35 371 audio_passthru_device(QDeepCopy<QString>(laudio_passthru_device)), 36 372 audio_passthru(false), audio_stretchfactor(1.0f), 37 373 374 audio_codec(NULL), 38 375 source(lsource), killaudio(false), 39 376 40 377 pauseaudio(false), audio_actually_paused(false), … … 46 383 47 384 src_ctx(NULL), 48 385 49 pSoundStretch(NULL), blocking(false), 386 pSoundStretch(NULL), 387 encoder(NULL), 388 blocking(false), 50 389 51 390 lastaudiolen(0), samples_buffered(0), 52 391 audiotime(0), … … 61 400 pthread_cond_init(&audio_bufsig, NULL); 62 401 63 402 output_audio = 0; // TODO FIXME Not POSIX compatible! 403 configured_audio_channels = gContext->GetNumSetting("MaxChannels", 2); 64 404 65 405 bzero(&src_data, sizeof(SRC_DATA)); 66 406 bzero(src_in, sizeof(float) * AUDIO_SRC_IN_SIZE); … … 108 448 VERBOSE(VB_GENERAL, LOC + QString("Using time stretch %1") 109 449 .arg(audio_stretchfactor)); 110 450 pSoundStretch = new soundtouch::SoundTouch(); 111 pSoundStretch->setSampleRate(audio_samplerate); 112 pSoundStretch->setChannels(audio_channels); 451 if (audio_codec) 452 { 453 if (!encoder) 454 { 455 VERBOSE(VB_AUDIO, LOC + QString("Creating Encoder for codec %1 origfs %2").arg(audio_codec->codec_id).arg(audio_codec->frame_size)); 456 encoder = new DigitalEncoder(); 457 if (!encoder->Init(audio_codec->codec_id, 458 audio_codec->bit_rate, 459 audio_codec->sample_rate, 460 audio_codec->channels 461 )) 462 { 463 // eeks 464 delete encoder; 465 encoder = NULL; 466 VERBOSE(VB_AUDIO, LOC + QString("Failed to Create Encoder")); 467 } 468 } 469 } 470 if (encoder) 471 { 472 pSoundStretch->setSampleRate(audio_codec->sample_rate); 473 pSoundStretch->setChannels(audio_codec->channels); 474 } 475 else 476 { 477 pSoundStretch->setSampleRate(audio_samplerate); 478 pSoundStretch->setChannels(audio_channels); 479 } 113 480 114 481 pSoundStretch->setTempo(audio_stretchfactor); 115 482 pSoundStretch->setSetting(SETTING_SEQUENCE_MS, 35); … … 132 499 } 133 500 134 501 void AudioOutputBase::Reconfigure(int laudio_bits, int laudio_channels, 135 int laudio_samplerate, bool laudio_passthru) 502 int laudio_samplerate, bool laudio_passthru, 503 void* laudio_codec) 136 504 { 505 int codec_id = CODEC_ID_NONE; 506 int lcodec_id = CODEC_ID_NONE; 507 int lcchannels = 0; 508 int cchannels = 0; 509 if (laudio_codec) 510 { 511 lcodec_id = ((AVCodecContext*)laudio_codec)->codec_id; 512 laudio_bits = 16; 513 laudio_channels = 2; 514 laudio_samplerate = 48000; 515 lcchannels = ((AVCodecContext*)laudio_codec)->channels; 516 } 517 if (audio_codec) 518 { 519 codec_id = audio_codec->codec_id; 520 cchannels = ((AVCodecContext*)audio_codec)->channels; 521 } 522 ClearError(); 137 523 if (laudio_bits == audio_bits && laudio_channels == audio_channels && 138 laudio_samplerate == audio_samplerate && 139 laudio_passthru == audio_passthru && !need_resampler) 524 laudio_samplerate == audio_samplerate && !need_resampler && 525 laudio_passthru == audio_passthru && 526 lcodec_id == codec_id && lcchannels == cchannels) 140 527 return; 141 528 142 529 KillAudio(); … … 148 535 waud = raud = 0; 149 536 audio_actually_paused = false; 150 537 538 bool redo_stretch = (pSoundStretch && audio_channels != laudio_channels); 151 539 audio_channels = laudio_channels; 152 540 audio_bits = laudio_bits; 153 541 audio_samplerate = laudio_samplerate; 542 audio_codec = (AVCodecContext*)laudio_codec; 154 543 audio_passthru = laudio_passthru; 155 544 if (audio_bits != 8 && audio_bits != 16) 156 545 { … … 169 558 170 559 numlowbuffer = 0; 171 560 561 VERBOSE(VB_GENERAL, QString("Opening audio device '%1'. ch %2 sr %3") 562 .arg(audio_main_device).arg(audio_channels).arg(audio_samplerate)); 563 172 564 // Actually do the device specific open call 173 565 if (!OpenDevice()) 174 566 { 175 567 VERBOSE(VB_AUDIO, LOC_ERR + "Aborting reconfigure"); 176 568 pthread_mutex_unlock(&avsync_lock); 177 569 pthread_mutex_unlock(&audio_buflock); 570 if (GetError().isEmpty()) 571 Error("Aborting reconfigure"); 572 VERBOSE(VB_AUDIO, "Aborting reconfigure"); 178 573 return; 179 574 } 180 575 … … 197 592 current_seconds = -1; 198 593 source_bitrate = -1; 199 594 595 // NOTE: this wont do anything as above samplerate vars are set equal 200 596 // Check if we need the resampler 201 597 if (audio_samplerate != laudio_samplerate) 202 598 { … … 221 617 222 618 VERBOSE(VB_AUDIO, LOC + QString("Audio Stretch Factor: %1") 223 619 .arg(audio_stretchfactor)); 620 VERBOSE(VB_AUDIO, QString("Audio Codec Used: %1") 621 .arg(audio_codec?codec_id_string(audio_codec->codec_id):"not set")); 224 622 225 SetStretchFactorLocked(audio_stretchfactor); 226 if (pSoundStretch) 623 if (redo_stretch) 227 624 { 228 pSoundStretch->setSampleRate(audio_samplerate); 229 pSoundStretch->setChannels(audio_channels); 625 float laudio_stretchfactor = audio_stretchfactor; 626 delete pSoundStretch; 627 pSoundStretch = NULL; 628 audio_stretchfactor = 0.0; 629 SetStretchFactorLocked(laudio_stretchfactor); 230 630 } 631 else 632 { 633 SetStretchFactorLocked(audio_stretchfactor); 634 if (pSoundStretch) 635 { 636 // if its passthru then we need to reencode 637 if (audio_codec) 638 { 639 if (!encoder) 640 { 641 VERBOSE(VB_AUDIO, LOC + QString("Creating Encoder for codec %1").arg(audio_codec->codec_id)); 642 encoder = new DigitalEncoder(); 643 if (!encoder->Init(audio_codec->codec_id, 644 audio_codec->bit_rate, 645 audio_codec->sample_rate, 646 audio_codec->channels 647 )) 648 { 649 // eeks 650 delete encoder; 651 encoder = NULL; 652 VERBOSE(VB_AUDIO, LOC + QString("Failed to Create Encoder")); 653 } 654 } 655 } 656 if (encoder) 657 { 658 pSoundStretch->setSampleRate(audio_codec->sample_rate); 659 pSoundStretch->setChannels(audio_codec->channels); 660 } 661 else 662 { 663 pSoundStretch->setSampleRate(audio_samplerate); 664 pSoundStretch->setChannels(audio_channels); 665 } 666 } 667 } 231 668 232 669 // Setup visualisations, zero the visualisations buffers 233 670 prepareVisuals(); … … 273 710 pSoundStretch = NULL; 274 711 } 275 712 713 if (encoder) 714 { 715 delete encoder; 716 encoder = NULL; 717 } 718 276 719 CloseDevice(); 277 720 278 721 killAudioLock.unlock(); … … 286 729 287 730 void AudioOutputBase::Pause(bool paused) 288 731 { 732 VERBOSE(VB_AUDIO, LOC+ QString("Pause %0").arg(paused)); 289 733 pauseaudio = paused; 290 734 audio_actually_paused = false; 291 735 } … … 368 812 The reason is that computing 'audiotime' requires acquiring the audio 369 813 lock, which the video thread should not do. So, we call 'SetAudioTime()' 370 814 from the audio thread, and then call this from the video thread. */ 371 intret;815 long long ret; 372 816 struct timeval now; 373 817 374 818 if (audiotime == 0) … … 380 824 381 825 ret = (now.tv_sec - audiotime_updated.tv_sec) * 1000; 382 826 ret += (now.tv_usec - audiotime_updated.tv_usec) / 1000; 383 ret = ( int)(ret * audio_stretchfactor);827 ret = (long long)(ret * audio_stretchfactor); 384 828 829 #if 1 830 VERBOSE(VB_AUDIO|VB_TIMESTAMP, 831 QString("GetAudiotime now=%1.%2, set=%3.%4, ret=%5, audt=%6 sf=%7") 832 .arg(now.tv_sec).arg(now.tv_usec) 833 .arg(audiotime_updated.tv_sec).arg(audiotime_updated.tv_usec) 834 .arg(ret) 835 .arg(audiotime) 836 .arg(audio_stretchfactor) 837 ); 838 #endif 839 385 840 ret += audiotime; 386 841 387 842 pthread_mutex_unlock(&avsync_lock); 388 return ret;843 return (int)ret; 389 844 } 390 845 391 846 void AudioOutputBase::SetAudiotime(void) … … 422 877 // include algorithmic latencies 423 878 if (pSoundStretch) 424 879 { 880 // add the effect of any unused but processed samples, AC3 reencode does this 881 totalbuffer += (int)(pSoundStretch->numSamples() * audio_bytes_per_sample); 425 882 // add the effect of unprocessed samples in time stretch algo 426 883 totalbuffer += (int)((pSoundStretch->numUnprocessedSamples() * 427 884 audio_bytes_per_sample) / audio_stretchfactor); 428 885 } 429 886 430 887 audiotime = audbuf_timecode - (int)(totalbuffer * 100000.0 / 431 888 (audio_bytes_per_sample * effdspstretched)); 432 889 433 890 gettimeofday(&audiotime_updated, NULL); 891 #if 1 892 VERBOSE(VB_AUDIO|VB_TIMESTAMP, 893 QString("SetAudiotime set=%1.%2, audt=%3 atc=%4 tb=%5 sb=%6 eds=%7 abps=%8 sf=%9") 894 .arg(audiotime_updated.tv_sec).arg(audiotime_updated.tv_usec) 895 .arg(audiotime) 896 .arg(audbuf_timecode) 897 .arg(totalbuffer) 898 .arg(soundcard_buffer) 899 .arg(effdspstretched) 900 .arg(audio_bytes_per_sample) 901 .arg(audio_stretchfactor) 902 ); 903 #endif 434 904 435 905 pthread_mutex_unlock(&avsync_lock); 436 906 pthread_mutex_unlock(&audio_buflock); … … 498 968 // NOTE: This function is not threadsafe 499 969 500 970 int afree = audiofree(true); 501 int len = samples * audio_bytes_per_sample;971 int len = samples * (encoder?encoder->audio_bytes_per_sample:audio_bytes_per_sample); 502 972 503 973 // Check we have enough space to write the data 504 974 if (need_resampler && src_ctx) … … 509 979 VERBOSE(VB_AUDIO|VB_TIMESTAMP, LOC + QString( 510 980 "AddSamples FAILED bytes=%1, used=%2, free=%3, timecode=%4") 511 981 .arg(len).arg(AUDBUFSIZE-afree).arg(afree) 512 .arg(timecode)); 513 982 .arg(LONGLONGCONVERT timecode)); 514 983 return false; // would overflow 515 984 } 516 985 … … 547 1016 548 1017 int AudioOutputBase::WaitForFreeSpace(int samples) 549 1018 { 550 int len = samples * audio_bytes_per_sample; 1019 int abps = encoder?encoder->audio_bytes_per_sample:audio_bytes_per_sample; 1020 int len = samples * abps; 551 1021 int afree = audiofree(false); 552 1022 553 1023 while (len > afree) 554 1024 { 555 1025 if (blocking) 556 1026 { 557 VERBOSE(VB_AUDIO , LOC + "Waiting for free space");1027 VERBOSE(VB_AUDIO|VB_TIMESTAMP, LOC + "Waiting for free space"); 558 1028 // wait for more space 559 1029 pthread_cond_wait(&audio_bufsig, &audio_buflock); 560 1030 afree = audiofree(false); 561 1031 } 562 1032 else 563 1033 { 564 VERBOSE(VB_IMPORTANT, LOC_ERR + 565 "Audio buffer overflow, audio data lost!"); 566 samples = afree / audio_bytes_per_sample; 567 len = samples * audio_bytes_per_sample; 1034 VERBOSE(VB_IMPORTANT, LOC_ERR + 1035 QString("Audio buffer overflow, %1 audio samples lost!") 1036 .arg(samples-afree / abps)); 1037 samples = afree / abps; 1038 len = samples * abps; 568 1039 if (src_ctx) 569 1040 { 570 1041 int error = src_reset(src_ctx); … … 589 1060 590 1061 int afree = audiofree(false); 591 1062 592 VERBOSE(VB_AUDIO|VB_TIMESTAMP, 593 LOC + QString("_AddSamples bytes=%1, used=%2, free=%3, timecode=%4") 594 .arg(samples * audio_bytes_per_sample) 595 .arg(AUDBUFSIZE-afree).arg(afree).arg((long)timecode)); 1063 int abps = encoder?encoder->audio_bytes_per_sample:audio_bytes_per_sample; 1064 VERBOSE(VB_AUDIO|VB_TIMESTAMP, 1065 LOC + QString("_AddSamples samples=%1 bytes=%2, used=%3, free=%4, timecode=%5") 1066 .arg(samples) 1067 .arg(samples * abps) 1068 .arg(AUDBUFSIZE-afree).arg(afree).arg(LONGLONGCONVERT timecode)); 596 1069 597 1070 len = WaitForFreeSpace(samples); 598 1071 … … 629 1102 630 1103 if (pSoundStretch) 631 1104 { 1105 632 1106 // does not change the timecode, only the number of samples 633 1107 // back to orig pos 634 1108 org_waud = waud; 635 1109 int bdiff = AUDBUFSIZE - org_waud; 636 int nSamplesToEnd = bdiff/a udio_bytes_per_sample;1110 int nSamplesToEnd = bdiff/abps; 637 1111 if (bdiff < len) 638 1112 { 639 1113 pSoundStretch->putSamples((soundtouch::SAMPLETYPE*)(audiobuffer + 640 1114 org_waud), nSamplesToEnd); 641 1115 pSoundStretch->putSamples((soundtouch::SAMPLETYPE*)audiobuffer, 642 (len - bdiff) / a udio_bytes_per_sample);1116 (len - bdiff) / abps); 643 1117 } 644 1118 else 645 1119 { 646 1120 pSoundStretch->putSamples((soundtouch::SAMPLETYPE*)(audiobuffer + 647 org_waud), len / a udio_bytes_per_sample);1121 org_waud), len / abps); 648 1122 } 649 1123 650 int newLen = 0; 651 int nSamples; 652 len = WaitForFreeSpace(pSoundStretch->numSamples() * 653 audio_bytes_per_sample); 654 do 1124 if (encoder) 655 1125 { 656 int samplesToGet = len/audio_bytes_per_sample; 657 if (samplesToGet > nSamplesToEnd) 1126 // pull out a packet's worth and reencode it until we dont have enough 1127 // for any more packets 1128 soundtouch::SAMPLETYPE* temp_buff = 1129 (soundtouch::SAMPLETYPE*)encoder->GetFrameBuffer(); 1130 size_t frameSize = encoder->FrameSize()/abps; 1131 VERBOSE(VB_AUDIO|VB_TIMESTAMP, 1132 QString("_AddSamples Enc sfs=%1 bfs=%2 sss=%3") 1133 .arg(frameSize) 1134 .arg(encoder->FrameSize()) 1135 .arg(pSoundStretch->numSamples()) 1136 ); 1137 // process the same number of samples as it creates a full encoded buffer 1138 // just like before 1139 while (pSoundStretch->numSamples() >= frameSize) 658 1140 { 659 samplesToGet = nSamplesToEnd; 1141 int got = pSoundStretch->receiveSamples(temp_buff, frameSize); 1142 int amount = encoder->Encode(temp_buff); 1143 VERBOSE(VB_AUDIO|VB_TIMESTAMP, 1144 QString("_AddSamples Enc bytes=%1 got=%2 left=%3") 1145 .arg(amount) 1146 .arg(got) 1147 .arg(pSoundStretch->numSamples()) 1148 ); 1149 if (amount == 0) 1150 continue; 1151 //len = WaitForFreeSpace(amount); 1152 char * ob = encoder->GetOutBuff(); 1153 if (amount >= bdiff) 1154 { 1155 memcpy(audiobuffer + org_waud, ob, bdiff); 1156 ob += bdiff; 1157 amount -= bdiff; 1158 org_waud = 0; 1159 } 1160 if (amount > 0) 1161 memcpy(audiobuffer + org_waud, ob, amount); 1162 bdiff = AUDBUFSIZE - amount; 1163 org_waud += amount; 660 1164 } 661 662 nSamples = pSoundStretch->receiveSamples((soundtouch::SAMPLETYPE*) 663 (audiobuffer + org_waud), samplesToGet); 664 if (nSamples == nSamplesToEnd) 1165 } 1166 else 1167 { 1168 int newLen = 0; 1169 int nSamples; 1170 len = WaitForFreeSpace(pSoundStretch->numSamples() * 1171 audio_bytes_per_sample); 1172 do 665 1173 { 666 org_waud = 0; 667 nSamplesToEnd = AUDBUFSIZE/audio_bytes_per_sample; 668 } 669 else 670 { 671 org_waud += nSamples * audio_bytes_per_sample; 672 nSamplesToEnd -= nSamples; 673 } 1174 int samplesToGet = len/audio_bytes_per_sample; 1175 if (samplesToGet > nSamplesToEnd) 1176 { 1177 samplesToGet = nSamplesToEnd; 1178 } 674 1179 675 newLen += nSamples * audio_bytes_per_sample; 676 len -= nSamples * audio_bytes_per_sample; 677 } while (nSamples > 0); 1180 nSamples = pSoundStretch->receiveSamples((soundtouch::SAMPLETYPE*) 1181 (audiobuffer + org_waud), samplesToGet); 1182 if (nSamples == nSamplesToEnd) 1183 { 1184 org_waud = 0; 1185 nSamplesToEnd = AUDBUFSIZE/audio_bytes_per_sample; 1186 } 1187 else 1188 { 1189 org_waud += nSamples * audio_bytes_per_sample; 1190 nSamplesToEnd -= nSamples; 1191 } 1192 1193 newLen += nSamples * audio_bytes_per_sample; 1194 len -= nSamples * audio_bytes_per_sample; 1195 } while (nSamples > 0); 1196 } 678 1197 } 679 1198 680 1199 waud = org_waud; … … 750 1269 space_on_soundcard = getSpaceOnSoundcard(); 751 1270 752 1271 if (space_on_soundcard != last_space_on_soundcard) { 753 VERBOSE(VB_AUDIO , LOC + QString("%1 bytes free on soundcard")1272 VERBOSE(VB_AUDIO|VB_TIMESTAMP, LOC + QString("%1 bytes free on soundcard") 754 1273 .arg(space_on_soundcard)); 755 1274 last_space_on_soundcard = space_on_soundcard; 756 1275 } … … 763 1282 WriteAudio(zeros, fragment_size); 764 1283 } else { 765 1284 // this should never happen now -dag 766 VERBOSE(VB_AUDIO , LOC +1285 VERBOSE(VB_AUDIO|VB_TIMESTAMP, LOC + 767 1286 QString("waiting for space on soundcard " 768 1287 "to write zeros: have %1 need %2") 769 1288 .arg(space_on_soundcard).arg(fragment_size)); … … 799 1318 if (fragment_size > audiolen(true)) 800 1319 { 801 1320 if (audiolen(true) > 0) // only log if we're sending some audio 802 VERBOSE(VB_AUDIO , LOC +1321 VERBOSE(VB_AUDIO|VB_TIMESTAMP, LOC + 803 1322 QString("audio waiting for buffer to fill: " 804 1323 "have %1 want %2") 805 1324 .arg(audiolen(true)).arg(fragment_size)); 806 1325 807 VERBOSE(VB_AUDIO, LOC + "Broadcasting free space avail");1326 //VERBOSE(VB_AUDIO|VB_TIMESTAMP, LOC + "Broadcasting free space avail"); 808 1327 pthread_mutex_lock(&audio_buflock); 809 1328 pthread_cond_broadcast(&audio_bufsig); 810 1329 pthread_mutex_unlock(&audio_buflock); … … 818 1337 if (fragment_size > space_on_soundcard) 819 1338 { 820 1339 if (space_on_soundcard != last_space_on_soundcard) { 821 VERBOSE(VB_AUDIO , LOC +1340 VERBOSE(VB_AUDIO|VB_TIMESTAMP, LOC + 822 1341 QString("audio waiting for space on soundcard: " 823 1342 "have %1 need %2") 824 1343 .arg(space_on_soundcard).arg(fragment_size)); … … 880 1399 881 1400 /* update raud */ 882 1401 raud = (raud + fragment_size) % AUDBUFSIZE; 883 VERBOSE(VB_AUDIO, LOC + "Broadcasting free space avail");1402 //VERBOSE(VB_AUDIO|VB_TIMESTAMP, LOC + "Broadcasting free space avail"); 884 1403 pthread_cond_broadcast(&audio_bufsig); 885 1404 886 1405 written_size = fragment_size; -
libs/libmyth/audiooutputalsa.cpp
49 49 QString real_device = (audio_passthru) ? 50 50 audio_passthru_device : audio_main_device; 51 51 52 int index; 53 if ((index=real_device.find('|'))>=0) 54 { 55 if (audio_channels != 2) 56 real_device = real_device.mid(index+1); 57 else 58 real_device = real_device.left(index); 59 } 60 52 61 VERBOSE(VB_GENERAL, QString("Opening ALSA audio device '%1'.") 53 62 .arg(real_device)); 54 63 … … 86 95 } 87 96 else 88 97 { 89 fragment_size = 6144; // nicely divisible by 2,4,6,8 channels @ 16-bits 90 buffer_time = 500000; // .5 seconds 98 //fragment_size = 6144; // nicely divisible by 2,4,6,8 channels @ 16-bits 99 //fragment_size = 3072*audio_channels; // nicely divisible by 2,4,6,8 channels @ 16-bits 100 fragment_size = (audio_bits * audio_channels * audio_samplerate) / (8*30); 101 buffer_time = 100000; // .5 seconds 91 102 period_time = buffer_time / 4; // 4 interrupts per buffer 92 103 } 93 104 … … 159 170 160 171 tmpbuf = aubuf; 161 172 162 VERBOSE(VB_AUDIO , QString("WriteAudio: Preparing %1 bytes (%2 frames)")173 VERBOSE(VB_AUDIO|VB_TIMESTAMP, QString("WriteAudio: Preparing %1 bytes (%2 frames)") 163 174 .arg(size).arg(frames)); 164 175 165 176 while (frames > 0) -
programs/mythfrontend/globalsettings.cpp
39 39 dev.setNameFilter("adsp*"); 40 40 gc->fillSelectionsFromDir(dev); 41 41 } 42 #ifdef USE_ALSA 43 gc->addSelection("ALSA:default", "ALSA:default"); 44 gc->addSelection("ALSA:analog", "ALSA:analog"); 45 gc->addSelection("ALSA:digital", "ALSA:digital"); 46 gc->addSelection("ALSA:mixed-analog", "ALSA:mixed-analog"); 47 gc->addSelection("ALSA:mixed-digital", "ALSA:mixed-digital"); 48 #endif 49 #ifdef USE_ARTS 50 gc->addSelection("ARTS:", "ARTS:"); 51 #endif 52 #ifdef USE_JACK 53 gc->addSelection("JACK:output", "JACK:output"); 54 #endif 55 gc->addSelection("NULL", "NULL"); 42 56 43 57 return gc; 44 58 } 45 59 60 static HostComboBox *MaxAudioChannels() 61 { 62 HostComboBox *gc = new HostComboBox("MaxChannels",false); 63 gc->setLabel(QObject::tr("Max Audio Channels")); 64 //gc->addSelection(QObject::tr("Mono"), "1"); 65 //gc->addSelection(QObject::tr("Stereo L+R"), "2", true); // default 66 //gc->addSelection(QObject::tr("3 Channel: L C R"), "3"); 67 //gc->addSelection(QObject::tr("4 Channel: L R LS RS"), "4"); 68 //gc->addSelection(QObject::tr("5 Channel: L C R LS RS"), "5"); 69 //gc->addSelection(QObject::tr("6 Channel: L C R LS RS LFE"), "6"); 70 gc->addSelection(QObject::tr("Stereo"), "2", true); // default 71 gc->addSelection(QObject::tr("6 Channel"), "6"); 72 gc->setHelpText( 73 QObject::tr("Set the maximum number of audio channels to be decoded. " 74 "This is for multi-channel/surround audio playback.")); 75 return gc; 76 } 77 46 78 static HostComboBox *PassThroughOutputDevice() 47 79 { 48 80 HostComboBox *gc = new HostComboBox("PassThruOutputDevice", true); … … 2487 2519 #ifdef CONFIG_LIBDTS 2488 2520 vgrp0->addChild(DTSPassThrough()); 2489 2521 #endif 2522 addChild(MaxAudioChannels()); 2490 2523 2491 2524 VerticalConfigurationGroup *vgrp1 = 2492 2525 new VerticalConfigurationGroup(false, false, true, true); -
programs/mythtranscode/transcode.cpp
55 55 56 56 // reconfigure sound out for new params 57 57 virtual void Reconfigure(int audio_bits, int audio_channels, 58 int audio_samplerate, bool audio_passthru) 58 int audio_samplerate, bool audio_passthru, 59 void * = NULL) 59 60 { 61 ClearError(); 60 62 (void)audio_samplerate; 61 63 (void)audio_passthru; 62 64 bits = audio_bits; 63 65 channels = audio_channels; 64 66 bytes_per_sample = bits * channels / 8; 67 if (channels>2) 68 Error("Invalid channel count"); 65 69 } 66 70 67 71 // dsprate is in 100 * samples/second -
programs/mythuitest/mythuitest.pro
1 1 INCLUDEPATH += ../../libs/libmythui ../../libs/libmyth 2 2 3 LIBS += -L../../libs/libmyth -L../../libs/libmythui 3 LIBS += -L../../libs/libmyth -L../../libs/libmythui -L../../libs/libavcodec -L../../libs/libavutil 4 4 5 5 include ( ../../config.mak ) 6 6 include ( ../../settings.pro ) … … 9 9 TARGET = mythuitest 10 10 CONFIG += thread opengl 11 11 12 LIBS += -lmythui-$$LIBVERSION -lmyth-$$LIBVERSION $$EXTRA_LIBS12 LIBS += -lmythui-$$LIBVERSION -lmyth-$$LIBVERSION -lmythavcodec-$$LIBVERSION -lmythavutil-$$LIBVERSION $$EXTRA_LIBS 13 13 14 14 isEmpty(QMAKE_EXTENSION_SHLIB) { 15 15 QMAKE_EXTENSION_SHLIB=so … … 19 19 } 20 20 TARGETDEPS += ../../libs/libmythui/libmythui-$${LIBVERSION}.$${QMAKE_EXTENSION_SHLIB} 21 21 TARGETDEPS += ../../libs/libmyth/libmyth-$${LIBVERSION}.$${QMAKE_EXTENSION_SHLIB} 22 TARGETDEPS += ../../libs/libavcodec/libmythavcodec-$${LIBVERSION}.$${QMAKE_EXTENSION_SHLIB} 23 TARGETDEPS += ../../libs/libavutil/libmythavutil-$${LIBVERSION}.$${QMAKE_EXTENSION_SHLIB} 22 24 23 25 macx { 24 26 # Duplication of source with libmyth (e.g. oldsettings.cpp) -
libs/libmythtv/avformatdecoder.h
248 248 bool allow_ac3_passthru; 249 249 bool allow_dts_passthru; 250 250 bool disable_passthru; 251 int max_channels; 251 252 252 253 AudioInfo audioIn; 253 254 AudioInfo audioOut; -
libs/libmythtv/avformatdecoder.cpp
47 47 #define MAX_AC3_FRAME_SIZE 6144 48 48 49 49 /** Set to zero to allow any number of AC3 channels. */ 50 #define MAXCHANNELSELECT 1 51 #if MAXCHANNELSELECT 52 #define MAX_OUTPUT_CHANNELS compiler error 53 #else 50 54 #define MAX_OUTPUT_CHANNELS 2 55 #endif 51 56 52 57 static int cc608_parity(uint8_t byte); 53 58 static int cc608_good_parity(const int *parity_table, uint16_t data); … … 310 315 #ifdef CONFIG_LIBDTS 311 316 allow_dts_passthru = gContext->GetNumSetting("DTSPassThru", false); 312 317 #endif 318 max_channels = gContext->GetNumSetting("MaxChannels", 2); 313 319 314 320 audioIn.sample_size = -32; // force SetupAudioStream to run once 315 321 itv = GetNVP()->GetInteractiveTV(); … … 458 464 framesPlayed = lastKey; 459 465 framesRead = lastKey; 460 466 467 VERBOSE(VB_PLAYBACK, QString("AvFormatDecoder::DoFastForward newframe %5 frame %1 fps %2 ts %3 disc %4 cur_dts %6 adj %7 newts %8 fsa %9") 468 .arg(desiredFrame) 469 .arg(fps) 470 .arg(ts) 471 .arg(discardFrames) 472 .arg(framesPlayed) 473 .arg(st->cur_dts) 474 .arg(adj_cur_dts) 475 .arg(newts) 476 .arg(frameseekadjust) 477 ); 478 461 479 int normalframes = desiredFrame - framesPlayed; 462 480 normalframes = max(normalframes, 0); 481 #if 0 482 if (!exactseeks) 483 normalframes = 0; 484 #endif 485 463 486 SeekReset(lastKey, normalframes, discardFrames, discardFrames); 464 487 465 488 if (discardFrames) … … 546 569 // Skip all the desired number of skipFrames 547 570 for (;skipFrames > 0 && !ateof; skipFrames--) 548 571 { 549 GetFrame(0);572 GetFrame(0); 550 573 if (decoded_video_frame) 551 574 GetNVP()->DiscardVideoFrame(decoded_video_frame); 552 575 } … … 777 800 778 801 fmt->flags &= ~AVFMT_NOFILE; 779 802 803 #if 1 804 if ((m_playbackinfo) || livetv || watchingrecording) 805 { 806 const char *name = ic->av_class->item_name(ic); 807 VERBOSE(VB_GENERAL, QString("libavformat type %1").arg(name)); 808 } 809 #endif 810 811 //struct timeval one, two, res; 812 //gettimeofday(&one, NULL); 813 780 814 if (!ringBuffer->isDVD() && !livetv) 781 815 av_estimate_timings(ic, 0); 782 816 … … 787 821 if (-1 == ret) 788 822 return ret; 789 823 824 // make sure its at the real start due to av_find_stream_info reading 825 if (!livetv) 826 { 827 ret = av_seek_frame(ic, -1, 0, AVSEEK_FLAG_BACKWARD); 828 //if (ret < 0) 829 // av_seek_frame(ic, -1, 0, AVSEEK_FLAG_BYTE); // reposition to start of stream 830 } 831 790 832 AutoSelectTracks(); // This is needed for transcoder 791 833 792 834 { … … 816 858 // If we don't have a position map, set up ffmpeg for seeking 817 859 if (!recordingHasPositionMap) 818 860 { 861 const char *name = ic->av_class->item_name(ic); 819 862 VERBOSE(VB_PLAYBACK, LOC + 820 "Recording has no position -- using libavformat seeking.");863 QString("Recording has no position -- using libavformat seeking. %1").arg(name)); 821 864 int64_t dur = ic->duration / (int64_t)AV_TIME_BASE; 822 865 823 866 if (dur > 0) … … 864 907 QString("Successfully opened decoder for file: " 865 908 "\"%1\". novideo(%2)").arg(filename).arg(novideo)); 866 909 910 // set initial position correctly 911 //DoFastForward(0, true); 912 867 913 // Return true if recording has position map 868 914 return recordingHasPositionMap; 869 915 } … … 1420 1466 <<") type ("<<codec_type_string(enc->codec_type) 1421 1467 <<") already open, leaving it alone."); 1422 1468 } 1469 #if MAXCHANNELSELECT 1470 if (enc->cqp != max_channels) 1471 { 1472 VERBOSE(VB_IMPORTANT, LOC + QString("Setting maxchannels to %1, %2").arg(max_channels).arg(enc->cqp)); 1473 enc->cqp = max_channels; 1474 } 1475 #endif 1423 1476 //assert(enc->codec_id); 1477 VERBOSE(VB_GENERAL, QString("AVFD: codec %1 has %2 channels").arg(codec_id_string(enc->codec_id)).arg(enc->channels)); 1478 #if 0 1479 if (enc->channels > 2) 1480 enc->channels = 2; 1481 #endif 1482 #if MAXCHANNELSELECT && 0 1483 if (enc->channels == 0) 1484 { 1485 //we have had a problem in parsing the codec params in this stream 1486 //enc->channels = max_channels; 1487 } 1488 #endif 1424 1489 1490 #if 0 1425 1491 // HACK BEGIN REALLY UGLY HACK FOR DTS PASSTHRU 1426 1492 if (enc->codec_id == CODEC_ID_DTS) 1427 1493 { … … 1430 1496 // enc->bit_rate = what??; 1431 1497 } 1432 1498 // HACK END REALLY UGLY HACK FOR DTS PASSTHRU 1499 #endif 1433 1500 1434 1501 bitrate += enc->bit_rate; 1435 1502 break; … … 2852 2919 2853 2920 AVStream *curstream = ic->streams[pkt->stream_index]; 2854 2921 2922 #if 0 2923 VERBOSE(VB_PLAYBACK|VB_TIMESTAMP, LOC + QString("timecode pts:%1 dts:%2 codec:%3") 2924 .arg(pkt->pts) 2925 .arg(pkt->dts) 2926 .arg((curstream && curstream->codec)?curstream->codec->codec_type:-1) 2927 ); 2928 #endif 2929 2855 2930 if (pkt->dts != (int64_t)AV_NOPTS_VALUE) 2856 2931 pts = (long long)(av_q2d(curstream->time_base) * pkt->dts * 1000); 2857 2932 … … 3050 3125 if (!curstream->codec->channels) 3051 3126 { 3052 3127 QMutexLocker locker(&avcodeclock); 3128 #if MAXCHANNELSELECT 3129 VERBOSE(VB_IMPORTANT, LOC + QString("Setting channels to %1").arg(audioOut.channels)); 3130 curstream->codec->cqp = max_channels; 3131 curstream->codec->channels = audioOut.channels; 3132 #else 3053 3133 curstream->codec->channels = MAX_OUTPUT_CHANNELS; 3134 #endif 3054 3135 ret = avcodec_decode_audio( 3055 3136 curstream->codec, audioSamples, 3056 3137 &data_size, ptr, len); 3057 3138 3058 3139 reselectAudioTrack |= curstream->codec->channels; 3059 3140 } 3141 #if MAXCHANNELSELECT 3142 if (curstream->codec->cqp != max_channels) 3143 { 3144 VERBOSE(VB_IMPORTANT, LOC + QString("Setting maxchannels to %1, %2").arg(max_channels).arg(curstream->codec->cqp)); 3145 curstream->codec->cqp = max_channels; 3146 } 3147 #endif 3060 3148 3061 3149 if (reselectAudioTrack) 3062 3150 { … … 3110 3198 { 3111 3199 AVCodecContext *ctx = curstream->codec; 3112 3200 3201 #if MAXCHANNELSELECT 3113 3202 if ((ctx->channels == 0) || 3203 (ctx->channels > audioOut.channels)) 3204 ctx->channels = audioOut.channels; 3205 #else 3206 if ((ctx->channels == 0) || 3114 3207 (ctx->channels > MAX_OUTPUT_CHANNELS)) 3115 3208 ctx->channels = MAX_OUTPUT_CHANNELS; 3209 #endif 3116 3210 3117 3211 ret = avcodec_decode_audio( 3118 3212 ctx, audioSamples, &data_size, ptr, len); … … 3455 3549 3456 3550 void AvFormatDecoder::SetDisablePassThrough(bool disable) 3457 3551 { 3552 #if MAXCHANNELSELECT 3553 // can only disable never reenable as once tiemstretch is on its on for the session 3554 if (disable_passthru) 3555 return; 3556 #endif 3458 3557 if (selectedTrack[kTrackTypeAudio].av_stream_index < 0) 3459 3558 { 3460 3559 disable_passthru = disable; 3461 3560 return; 3462 3561 } 3463 3562 3464 3563 if (disable != disable_passthru) 3465 3564 { 3466 3565 disable_passthru = disable; … … 3487 3586 AVCodecContext *codec_ctx = NULL; 3488 3587 AudioInfo old_in = audioIn; 3489 3588 AudioInfo old_out = audioOut; 3589 bool using_passthru = false; 3490 3590 3491 3591 if ((currentTrack[kTrackTypeAudio] >= 0) && 3492 3592 (selectedTrack[kTrackTypeAudio].av_stream_index <= … … 3496 3596 { 3497 3597 assert(curstream); 3498 3598 assert(curstream->codec); 3499 codec_ctx = curstream->codec; 3599 codec_ctx = curstream->codec; 3500 3600 bool do_ac3_passthru = (allow_ac3_passthru && !transcoding && 3501 !disable_passthru &&3502 3601 (codec_ctx->codec_id == CODEC_ID_AC3)); 3503 3602 bool do_dts_passthru = (allow_dts_passthru && !transcoding && 3504 !disable_passthru &&3505 3603 (codec_ctx->codec_id == CODEC_ID_DTS)); 3604 using_passthru = do_ac3_passthru || do_dts_passthru; 3506 3605 info = AudioInfo(codec_ctx->codec_id, 3507 3606 codec_ctx->sample_rate, codec_ctx->channels, 3508 do_ac3_passthru || do_dts_passthru);3607 using_passthru && !disable_passthru); 3509 3608 } 3510 3609 3511 3610 if (info == audioIn) 3512 3611 return false; // no change 3513 3612 3613 QString ptmsg = ""; 3614 if (using_passthru) 3615 { 3616 ptmsg = QString(" using passthru"); 3617 } 3514 3618 VERBOSE(VB_AUDIO, LOC + "Initializing audio parms from " + 3515 3619 QString("audio track #%1").arg(currentTrack[kTrackTypeAudio]+1)); 3516 3620 3517 3621 audioOut = audioIn = info; 3622 #if MAXCHANNELSELECT 3623 if (using_passthru) 3624 #else 3518 3625 if (audioIn.do_passthru) 3626 #endif 3519 3627 { 3520 3628 // A passthru stream looks like a 48KHz 2ch (@ 16bit) to the sound card 3521 audioOut.channels = 2; 3522 audioOut.sample_rate = 48000; 3523 audioOut.sample_size = 4; 3629 AudioInfo digInfo = audioOut; 3630 if (!disable_passthru) 3631 { 3632 digInfo.channels = 2; 3633 digInfo.sample_rate = 48000; 3634 digInfo.sample_size = 4; 3635 } 3636 if (audioOut.channels > max_channels) 3637 { 3638 audioOut.channels = max_channels; 3639 audioOut.sample_size = audioOut.channels * 2; 3640 codec_ctx->channels = audioOut.channels; 3641 } 3642 #if MAXCHANNELSELECT 3643 VERBOSE(VB_AUDIO, LOC + "Audio format changed digital passthrough " + 3644 QString("%1\n\t\t\tfrom %2 ; %3\n\t\t\tto %4 ; %5") 3645 .arg(digInfo.toString()) 3646 .arg(old_in.toString()).arg(old_out.toString()) 3647 .arg(audioIn.toString()).arg(audioOut.toString())); 3648 3649 if (digInfo.sample_rate > 0) 3650 GetNVP()->SetEffDsp(digInfo.sample_rate * 100); 3651 3652 //GetNVP()->SetAudioParams(audioOut.bps(), audioOut.channels, 3653 // audioOut.sample_rate); 3654 GetNVP()->SetAudioParams(digInfo.bps(), digInfo.channels, 3655 digInfo.sample_rate, audioIn.do_passthru); 3656 // allow the audio stuff to reencode 3657 GetNVP()->SetAudioCodec(codec_ctx); 3658 GetNVP()->ReinitAudio(); 3659 return true; 3660 #endif 3524 3661 } 3662 #if MAXCHANNELSELECT 3525 3663 else 3526 3664 { 3665 if (audioOut.channels > max_channels) 3666 { 3667 audioOut.channels = max_channels; 3668 audioOut.sample_size = audioOut.channels * 2; 3669 codec_ctx->channels = audioOut.channels; 3670 } 3671 } 3672 bool audiook; 3673 #if 0 3674 do 3675 { 3676 #endif 3677 #else 3678 else 3679 { 3527 3680 if (audioOut.channels > MAX_OUTPUT_CHANNELS) 3528 3681 { 3529 3682 audioOut.channels = MAX_OUTPUT_CHANNELS; … … 3531 3684 codec_ctx->channels = MAX_OUTPUT_CHANNELS; 3532 3685 } 3533 3686 } 3687 #endif 3534 3688 3535 3689 VERBOSE(VB_AUDIO, LOC + "Audio format changed " + 3536 3690 QString("\n\t\t\tfrom %1 ; %2\n\t\t\tto %3 ; %4") … … 3543 3697 GetNVP()->SetAudioParams(audioOut.bps(), audioOut.channels, 3544 3698 audioOut.sample_rate, 3545 3699 audioIn.do_passthru); 3546 GetNVP()->ReinitAudio(); 3700 // allow the audio stuff to reencode 3701 GetNVP()->SetAudioCodec(using_passthru?codec_ctx:NULL); 3702 QString errMsg = GetNVP()->ReinitAudio(); 3703 #if MAXCHANNELSELECT 3704 audiook = errMsg.isEmpty(); 3705 #if 0 3706 if (!audiook) 3707 { 3708 switch (audioOut.channels) 3709 { 3710 #if 0 3711 case 8: 3712 audioOut.channels = 6; 3713 break; 3714 #endif 3715 case 6: 3716 #if 0 3717 audioOut.channels = 5; 3718 break; 3719 case 5: 3720 audioOut.channels = 4; 3721 break; 3722 case 4: 3723 audioOut.channels = 3; 3724 break; 3725 case 3: 3726 #endif 3727 audioOut.channels = 2; 3728 break; 3729 #if 0 3730 case 2: 3731 audioOut.channels = 1; 3732 break; 3733 #endif 3734 default: 3735 // failed to reconfigure under any circumstances 3736 audiook = true; 3737 audioOut.channels = 0; 3738 break; 3739 } 3740 audioOut.sample_size = audioOut.channels * 2; 3741 codec_ctx->channels = audioOut.channels; 3742 } 3743 } while (!audiook); 3744 #endif 3745 #endif 3547 3746 3548 3747 return true; 3549 3748 } -
libs/libmythtv/NuppelVideoPlayer.h
127 127 void SetAudioInfo(const QString &main, const QString &passthru, uint rate); 128 128 void SetAudioParams(int bits, int channels, int samplerate, bool passthru); 129 129 void SetEffDsp(int dsprate); 130 void SetAudioCodec(void *ac); 130 131 131 132 // Sets 132 133 void SetParentWidget(QWidget *widget) { parentWidget = widget; } … … 677 678 int audio_bits; 678 679 int audio_samplerate; 679 680 float audio_stretchfactor; 681 void *audio_codec; 680 682 bool audio_passthru; 681 683 682 684 // Picture-in-Picture -
libs/libmythtv/NuppelVideoPlayer.cpp
206 206 audio_passthru_device(QString::null), 207 207 audio_channels(2), audio_bits(-1), 208 208 audio_samplerate(44100), audio_stretchfactor(1.0f), 209 audio_codec(NULL), 209 210 // Picture-in-Picture 210 211 pipplayer(NULL), setpipplayer(NULL), needsetpipplayer(false), 211 212 // Preview window support … … 723 724 if (audioOutput) 724 725 { 725 726 audioOutput->Reconfigure(audio_bits, audio_channels, 726 audio_samplerate, audio_passthru); 727 audio_samplerate, audio_passthru, 728 audio_codec); 727 729 errMsg = audioOutput->GetError(); 728 730 if (!errMsg.isEmpty()) 729 731 audioOutput->SetStretchFactor(audio_stretchfactor); … … 2178 2180 // decoding; display the frame, but don't wait for A/V Sync. 2179 2181 videoOutput->PrepareFrame(buffer, kScan_Intr2ndField); 2180 2182 videoOutput->Show(kScan_Intr2ndField); 2181 VERBOSE(VB_PLAYBACK , LOC + dbg + "skipping A/V wait.");2183 VERBOSE(VB_PLAYBACK|VB_TIMESTAMP, LOC + dbg + "skipping A/V wait."); 2182 2184 } 2183 2185 else 2184 2186 { 2185 2187 // If we are using software decoding, skip this frame altogether. 2188 //VERBOSE(VB_PLAYBACK|VB_TIMESTAMP, LOC + dbg + "dropping frame."); 2186 2189 VERBOSE(VB_PLAYBACK, LOC + dbg + "dropping frame to catch up."); 2187 2190 } 2188 2191 } … … 2192 2195 if (buffer) 2193 2196 videoOutput->PrepareFrame(buffer, ps); 2194 2197 2198 VERBOSE(VB_PLAYBACK|VB_TIMESTAMP, QString("AVSync waitforframe %1 %2").arg(avsync_adjustment).arg(m_double_framerate)); 2195 2199 videosync->WaitForFrame(avsync_adjustment); 2200 VERBOSE(VB_PLAYBACK|VB_TIMESTAMP, "AVSync show"); 2196 2201 if (!resetvideo) 2197 2202 videoOutput->Show(ps); 2198 2203 … … 2214 2219 2215 2220 // Display the second field 2216 2221 videosync->AdvanceTrigger(); 2217 videosync->WaitForFrame( 0);2222 videosync->WaitForFrame(avsync_adjustment); 2218 2223 if (!resetvideo) 2219 2224 { 2220 2225 videoOutput->Show(ps); … … 2242 2247 // If audio is way behind of video, adjust for it... 2243 2248 // by cutting the frame rate in half for the length of this frame 2244 2249 2245 avsync_adjustment = frame_interval; 2250 //avsync_adjustment = frame_interval; 2251 avsync_adjustment = refreshrate; 2246 2252 lastsync = true; 2253 //VERBOSE(VB_PLAYBACK|VB_TIMESTAMP, LOC + 2254 // QString("Video is %1 frames ahead of audio,\n" 2255 // "\t\t\tdoubling video frame interval.").arg(diverge)); 2247 2256 VERBOSE(VB_PLAYBACK, LOC + 2248 2257 QString("Video is %1 frames ahead of audio,\n" 2249 2258 "\t\t\tdoubling video frame interval to slow down.").arg(diverge)); … … 2252 2261 if (audioOutput && normal_speed) 2253 2262 { 2254 2263 long long currentaudiotime = audioOutput->GetAudiotime(); 2255 #if 02264 #if 1 2256 2265 VERBOSE(VB_PLAYBACK|VB_TIMESTAMP, QString( 2257 2266 "A/V timecodes audio %1 video %2 frameinterval %3 " 2258 2267 "avdel %4 avg %5 tcoffset %6") … … 2590 2599 2591 2600 usevideotimebase = gContext->GetNumSetting("UseVideoTimebase", 0); 2592 2601 2593 if ((print_verbose_messages & VB_PLAYBACK ) != 0)2602 if ((print_verbose_messages & VB_PLAYBACK|VB_TIMESTAMP) == (VB_PLAYBACK|VB_TIMESTAMP)) 2594 2603 output_jmeter = new Jitterometer("video_output", 100); 2595 2604 else 2596 2605 output_jmeter = NULL; … … 2636 2645 { 2637 2646 VERBOSE(VB_IMPORTANT, "Video sync method can't support double " 2638 2647 "framerate (refresh rate too low for bob deint)"); 2648 //m_scan = kScan_Ignore; 2649 //m_can_double = false; 2639 2650 FallbackDeint(); 2640 2651 } 2641 2652 } … … 3523 3534 audio_passthru = passthru; 3524 3535 } 3525 3536 3537 void NuppelVideoPlayer::SetAudioCodec(void* ac) 3538 { 3539 audio_codec = ac; 3540 } 3541 3526 3542 void NuppelVideoPlayer::SetEffDsp(int dsprate) 3527 3543 { 3528 3544 if (audioOutput) … … 3569 3585 tc_avcheck_framecounter++; 3570 3586 if (tc_avcheck_framecounter == 30) 3571 3587 { 3572 #define AUTO_RESYNC 13588 #define AUTO_RESYNC 0 3573 3589 #if AUTO_RESYNC 3574 3590 // something's terribly, terribly wrong. 3575 3591 if (tc_lastval[TC_AUDIO] < tc_lastval[TC_VIDEO] - 10000000 || -
libs/libavcodec/a52dec.c
143 143 } 144 144 } 145 145 146 static inline int16_t convert (int32_t i) 147 { 148 if (i > 0x43c07fff) 149 return 32767; 150 else if (i < 0x43bf8000) 151 return -32768; 152 else 153 return i - 0x43c00000; 154 } 155 156 void float2s16_2 (float * _f, int16_t * s16) 157 { 158 int i; 159 int32_t * f = (int32_t *) _f; 160 161 for (i = 0; i < 256; i++) { 162 s16[2*i] = convert (f[i]); 163 s16[2*i+1] = convert (f[i+256]); 164 } 165 } 166 167 void float2s16_4 (float * _f, int16_t * s16) 168 { 169 int i; 170 int32_t * f = (int32_t *) _f; 171 172 for (i = 0; i < 256; i++) { 173 s16[4*i] = convert (f[i]); 174 s16[4*i+1] = convert (f[i+256]); 175 s16[4*i+2] = convert (f[i+512]); 176 s16[4*i+3] = convert (f[i+768]); 177 } 178 } 179 180 void float2s16_5 (float * _f, int16_t * s16) 181 { 182 int i; 183 int32_t * f = (int32_t *) _f; 184 185 for (i = 0; i < 256; i++) { 186 s16[5*i] = convert (f[i]); 187 s16[5*i+1] = convert (f[i+256]); 188 s16[5*i+2] = convert (f[i+512]); 189 s16[5*i+3] = convert (f[i+768]); 190 s16[5*i+4] = convert (f[i+1024]); 191 } 192 } 193 194 int channels_multi (int flags) 195 { 196 if (flags & A52_LFE) 197 return 6; 198 else if (flags & 1) /* center channel */ 199 return 5; 200 else if ((flags & A52_CHANNEL_MASK) == A52_2F2R) 201 return 4; 202 else 203 return 2; 204 } 205 206 void float2s16_multi (float * _f, int16_t * s16, int flags) 207 { 208 int i; 209 int32_t * f = (int32_t *) _f; 210 211 switch (flags) { 212 case A52_MONO: 213 for (i = 0; i < 256; i++) { 214 s16[5*i] = s16[5*i+1] = s16[5*i+2] = s16[5*i+3] = 0; 215 s16[5*i+4] = convert (f[i]); 216 } 217 break; 218 case A52_CHANNEL: 219 case A52_STEREO: 220 case A52_DOLBY: 221 float2s16_2 (_f, s16); 222 break; 223 case A52_3F: 224 for (i = 0; i < 256; i++) { 225 s16[5*i] = convert (f[i]); 226 s16[5*i+1] = convert (f[i+512]); 227 s16[5*i+2] = s16[5*i+3] = 0; 228 s16[5*i+4] = convert (f[i+256]); 229 } 230 break; 231 case A52_2F2R: 232 float2s16_4 (_f, s16); 233 break; 234 case A52_3F2R: 235 float2s16_5 (_f, s16); 236 break; 237 case A52_MONO | A52_LFE: 238 for (i = 0; i < 256; i++) { 239 s16[6*i] = s16[6*i+1] = s16[6*i+2] = s16[6*i+3] = 0; 240 s16[6*i+4] = convert (f[i+256]); 241 s16[6*i+5] = convert (f[i]); 242 } 243 break; 244 case A52_CHANNEL | A52_LFE: 245 case A52_STEREO | A52_LFE: 246 case A52_DOLBY | A52_LFE: 247 for (i = 0; i < 256; i++) { 248 s16[6*i] = convert (f[i+256]); 249 s16[6*i+1] = convert (f[i+512]); 250 s16[6*i+2] = s16[6*i+3] = s16[6*i+4] = 0; 251 s16[6*i+5] = convert (f[i]); 252 } 253 break; 254 case A52_3F | A52_LFE: 255 for (i = 0; i < 256; i++) { 256 s16[6*i] = convert (f[i+256]); 257 s16[6*i+1] = convert (f[i+768]); 258 s16[6*i+2] = s16[6*i+3] = 0; 259 s16[6*i+4] = convert (f[i+512]); 260 s16[6*i+5] = convert (f[i]); 261 } 262 break; 263 case A52_2F2R | A52_LFE: 264 for (i = 0; i < 256; i++) { 265 s16[6*i] = convert (f[i+256]); 266 s16[6*i+1] = convert (f[i+512]); 267 s16[6*i+2] = convert (f[i+768]); 268 s16[6*i+3] = convert (f[i+1024]); 269 s16[6*i+4] = 0; 270 s16[6*i+5] = convert (f[i]); 271 } 272 break; 273 case A52_3F2R | A52_LFE: 274 for (i = 0; i < 256; i++) { 275 s16[6*i] = convert (f[i+256]); 276 s16[6*i+1] = convert (f[i+768]); 277 s16[6*i+2] = convert (f[i+1024]); 278 s16[6*i+3] = convert (f[i+1280]); 279 s16[6*i+4] = convert (f[i+512]); 280 s16[6*i+5] = convert (f[i]); 281 } 282 break; 283 } 284 } 285 286 146 287 /**** end */ 147 288 148 289 #define HEADER_SIZE 7 … … 168 309 len = s->inbuf_ptr - s->inbuf; 169 310 if (s->frame_size == 0) { 170 311 /* no header seen : find one. We need at least 7 bytes to parse it */ 312 //av_log(avctx, AV_LOG_DEBUG, "ac3dec: no frame processing, len %d buf_size %d\n",len,buf_size); 171 313 len = HEADER_SIZE - len; 172 314 if (len > buf_size) 173 315 len = buf_size; … … 186 328 /* update codec info */ 187 329 avctx->sample_rate = sample_rate; 188 330 s->channels = ac3_channels[s->flags & 7]; 331 if (avctx->cqp >= 0) 332 avctx->channels = avctx->cqp; 189 333 if (s->flags & A52_LFE) 190 334 s->channels++; 191 335 if (avctx->channels == 0) 192 336 /* No specific number of channel requested */ 193 337 avctx->channels = s->channels; 194 338 else if (s->channels < avctx->channels) { 195 av_log(avctx, AV_LOG_ERROR, "ac3dec: AC3 Source channels are less than specified: output to %d channels.. (frmsize: %d)\n", s->channels, len);339 //av_log(avctx, AV_LOG_ERROR, "ac3dec: AC3 Source channels are less than specified: output to %d channels.. (frmsize: %d)\n", s->channels, len); 196 340 avctx->channels = s->channels; 197 341 } 198 342 avctx->bit_rate = bit_rate; … … 208 352 s->inbuf_ptr += len; 209 353 buf_size -= len; 210 354 } else { 355 int chans; 211 356 flags = s->flags; 212 357 if (avctx->channels == 1) 213 358 flags = A52_MONO; 214 else if (avctx->channels == 2) 215 flags = A52_STEREO; 359 else if (avctx->channels == 2) { 360 if (s->channels>2) 361 flags = A52_DOLBY; 362 else 363 flags = A52_STEREO; 364 } 216 365 else 217 366 flags |= A52_ADJUST_LEVEL; 218 367 level = 1; 368 chans = channels_multi(flags); 219 369 if (s->a52_frame(s->state, s->inbuf, &flags, &level, 384)) { 220 370 fail: 221 371 av_log(avctx, AV_LOG_ERROR, "Error decoding frame\n"); … … 226 376 for (i = 0; i < 6; i++) { 227 377 if (s->a52_block(s->state)) 228 378 goto fail; 229 float _to_int(s->samples, out_samples + i * 256 * avctx->channels, avctx->channels);379 float2s16_multi(s->samples, out_samples + i * 256 * chans, flags); 230 380 } 231 381 s->inbuf_ptr = s->inbuf; 232 382 s->frame_size = 0; 233 *data_size = 6 * avctx->channels * 256 * sizeof(int16_t);383 *data_size = 6 * chans * 256 * sizeof(int16_t); 234 384 break; 235 385 } 236 386 } -
libs/libavcodec/ac3enc.c
1152 1152 { 1153 1153 AC3EncodeContext *s = avctx->priv_data; 1154 1154 int16_t *samples = data; 1155 // expects L C R LS RS LFE 1156 // audio format is L R LS RS C LFE 1157 static int channel_index[6] = { 0, 4, 1, 2, 3, 5 }; 1158 /* 1159 * A52->Analog->AC3Enc 1160 * 1->0->0 1161 * 3->1->2 1162 * 4->2->3 1163 * 5->3->4 1164 * 2->4->1 1165 * 0->5->5 1166 */ 1155 1167 int i, j, k, v, ch; 1156 1168 int16_t input_samples[N]; 1157 1169 int32_t mdct_coef[NB_BLOCKS][AC3_MAX_CHANNELS][N/2]; … … 1172 1184 /* compute input samples */ 1173 1185 memcpy(input_samples, s->last_samples[ch], N/2 * sizeof(int16_t)); 1174 1186 sinc = s->nb_all_channels; 1175 sptr = samples + (sinc * (N/2) * i) + ch ;1187 sptr = samples + (sinc * (N/2) * i) + channel_index[ch]; 1176 1188 for(j=0;j<N/2;j++) { 1177 1189 v = *sptr; 1178 1190 input_samples[j + N/2] = v;