Ticket #1104: mythtv_ac3.18.patch
File mythtv_ac3.18.patch, 66.3 KB (added by , 18 years ago) |
---|
-
libs/libmyth/libmyth.pro
33 33 SOURCES += DisplayResScreen.cpp util-x11.cpp qmdcodec.cpp 34 34 SOURCES += virtualkeyboard.cpp mythobservable.cpp mythsocket.cpp 35 35 36 #INCLUDEPATH += ../libmythsamplerate ../libmythsoundtouch ../.. 37 #INCLUDEPATH += ../libavutil .. 38 #DEPENDPATH += ../libmythsamplerate ../libmythsoundtouch 36 39 INCLUDEPATH += ../libmythsamplerate ../libmythsoundtouch ../.. ../ 40 INCLUDEPATH += ../libavutil 37 41 DEPENDPATH += ../libmythsamplerate ../libmythsoundtouch ../ ../libmythui 42 DEPENDPATH += ../libavutil ../libavcodec 38 43 39 44 LIBS += -L../libmythsamplerate -lmythsamplerate-$${LIBVERSION} 40 45 LIBS += -L../libmythsoundtouch -lmythsoundtouch-$${LIBVERSION} 46 LIBS += -L../libavcodec -lmythavcodec-$${LIBVERSION} 41 47 42 48 isEmpty(QMAKE_EXTENSION_SHLIB) { 43 49 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); … … 120 129 bool audio_passthru; 121 130 122 131 float audio_stretchfactor; 132 AVCodecContext *audio_codec; 123 133 AudioOutputSource source; 124 134 125 135 bool killaudio; … … 128 138 bool set_initial_vol; 129 139 bool buffer_output_data_for_use; // used by AudioOutputNULL 130 140 141 int configured_audio_channels; 142 131 143 private: 132 144 // resampler 133 145 bool need_resampler; … … 139 151 140 152 // timestretch 141 153 soundtouch::SoundTouch * pSoundStretch; 154 DigitalEncoder * encoder; 142 155 143 156 bool blocking; // do AddSamples calls block? 144 157 … … 155 168 156 169 pthread_mutex_t avsync_lock; /* must hold avsync_lock to read or write 157 170 'audiotime' and 'audiotime_updated' */ 158 intaudiotime; // timecode of audio leaving the soundcard (same units as171 long long audiotime; // timecode of audio leaving the soundcard (same units as 159 172 // timecodes) ... 160 173 struct timeval audiotime_updated; // ... which was last updated at this time 161 174 162 175 /* Audio circular buffer */ 163 176 unsigned char audiobuffer[AUDBUFSIZE]; /* buffer */ 164 177 int raud, waud; /* read and write positions */ 165 intaudbuf_timecode; /* timecode of audio most recently placed into178 long long audbuf_timecode; /* timecode of audio most recently placed into 166 179 buffer */ 167 180 168 181 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 } 23 24 #if QT_VERSION < 0x030200 25 #define LONGLONGCONVERT (long) 26 #else 27 #define LONGLONGCONVERT 28 #endif 29 30 #define LOC QString("DEnc: "); 31 #define MAX_AC3_FRAME_SIZE 6144 32 class DigitalEncoder 33 { 34 public: 35 DigitalEncoder(); 36 ~DigitalEncoder(); 37 void Dispose(); 38 bool DigitalEncoder::Init(CodecID codec_id, int bitrate, int samplerate, int channels); 39 size_t Encode(short * buff); 40 41 // if needed 42 char * GetFrameBuffer() 43 { 44 if (!frame_buffer && av_context) 45 { 46 frame_buffer = new char [one_frame_bytes]; 47 } 48 return frame_buffer; 49 } 50 size_t FrameSize() const { return one_frame_bytes; } 51 char * GetOutBuff() const { return outbuf; } 52 53 size_t audio_bytes_per_sample; 54 private: 55 AVCodecContext *av_context; 56 char * outbuf; 57 char * frame_buffer; 58 int outbuf_size; 59 size_t one_frame_bytes; 60 }; 61 62 DigitalEncoder::DigitalEncoder() 63 { 64 av_context = NULL; 65 outbuf = NULL; 66 outbuf_size = 0; 67 one_frame_bytes = 0; 68 frame_buffer = NULL; 69 } 70 71 DigitalEncoder::~DigitalEncoder() 72 { 73 Dispose(); 74 } 75 76 void DigitalEncoder::Dispose() 77 { 78 if (av_context) 79 { 80 avcodec_close(av_context); 81 av_free(av_context); 82 av_context = NULL; 83 } 84 if (outbuf) 85 { 86 delete [] outbuf; 87 outbuf = NULL; 88 outbuf_size = 0; 89 } 90 if (frame_buffer) 91 { 92 delete [] frame_buffer; 93 frame_buffer = NULL; 94 one_frame_bytes = 0; 95 } 96 } 97 98 //CODEC_ID_AC3 99 bool DigitalEncoder::Init(CodecID codec_id, int bitrate, int samplerate, int channels) 100 { 101 AVCodec * codec; 102 int ret; 103 104 VERBOSE(VB_AUDIO, QString("DigitalEncoder::Init codecid=%1, br=%2, sr=%3, ch=%4") 105 .arg(codec_id_string(codec_id)) 106 .arg(bitrate) 107 .arg(samplerate) 108 .arg(channels)); 109 //codec = avcodec_find_encoder(codec_id); 110 // always AC3 as there is no DTS encoder at the moment 2005/1/9 111 codec = avcodec_find_encoder(CODEC_ID_AC3); 112 if (!codec) 113 { 114 VERBOSE(VB_IMPORTANT,"Error: could not find codec"); 115 return false; 116 } 117 av_context = avcodec_alloc_context(); 118 av_context->bit_rate = bitrate; 119 av_context->sample_rate = samplerate; 120 av_context->channels = channels; 121 // open it */ 122 if ((ret = avcodec_open(av_context, codec)) < 0) 123 { 124 VERBOSE(VB_IMPORTANT,"Error: could not open codec, invalid bitrate or samplerate"); 125 Dispose(); 126 return false; 127 } 128 129 size_t bytes_per_frame = av_context->channels * sizeof(short); 130 audio_bytes_per_sample = bytes_per_frame; 131 one_frame_bytes = bytes_per_frame * av_context->frame_size; 132 133 outbuf_size = 16384; // ok for AC3 but DTS? 134 outbuf = new char [outbuf_size]; 135 VERBOSE(VB_AUDIO, QString("DigitalEncoder::Init fs=%1, bpf=%2 ofb=%3") 136 .arg(av_context->frame_size) 137 .arg(bytes_per_frame) 138 .arg(one_frame_bytes) 139 ); 140 141 return true; 142 } 143 144 static int DTS_SAMPLEFREQS[16] = 145 { 146 0, 8000, 16000, 32000, 64000, 128000, 11025, 22050, 147 44100, 88200, 176400, 12000, 24000, 48000, 96000, 192000 148 }; 149 150 static int DTS_BITRATES[30] = 151 { 152 32000, 56000, 64000, 96000, 112000, 128000, 153 192000, 224000, 256000, 320000, 384000, 448000, 154 512000, 576000, 640000, 768000, 896000, 1024000, 155 1152000, 1280000, 1344000, 1408000, 1411200, 1472000, 156 1536000, 1920000, 2048000, 3072000, 3840000, 4096000 157 }; 158 159 static int dts_decode_header(uint8_t *indata_ptr, int *rate, 160 int *nblks, int *sfreq) 161 { 162 uint id = ((indata_ptr[0] << 24) | (indata_ptr[1] << 16) | 163 (indata_ptr[2] << 8) | (indata_ptr[3])); 164 165 if (id != 0x7ffe8001) 166 return -1; 167 168 int ftype = indata_ptr[4] >> 7; 169 170 int surp = (indata_ptr[4] >> 2) & 0x1f; 171 surp = (surp + 1) % 32; 172 173 *nblks = (indata_ptr[4] & 0x01) << 6 | (indata_ptr[5] >> 2); 174 ++*nblks; 175 176 int fsize = (indata_ptr[5] & 0x03) << 12 | 177 (indata_ptr[6] << 4) | (indata_ptr[7] >> 4); 178 ++fsize; 179 180 *sfreq = (indata_ptr[8] >> 2) & 0x0f; 181 *rate = (indata_ptr[8] & 0x03) << 3 | ((indata_ptr[9] >> 5) & 0x07); 182 183 if (ftype != 1) 184 { 185 VERBOSE(VB_IMPORTANT, LOC + 186 QString("DTS: Termination frames not handled (ftype %1)") 187 .arg(ftype)); 188 return -1; 189 } 190 191 if (*sfreq != 13) 192 { 193 VERBOSE(VB_IMPORTANT, LOC + 194 QString("DTS: Only 48kHz supported (sfreq %1)").arg(*sfreq)); 195 return -1; 196 } 197 198 if ((fsize > 8192) || (fsize < 96)) 199 { 200 VERBOSE(VB_IMPORTANT, LOC + 201 QString("DTS: fsize: %1 invalid").arg(fsize)); 202 return -1; 203 } 204 205 if (*nblks != 8 && *nblks != 16 && *nblks != 32 && 206 *nblks != 64 && *nblks != 128 && ftype == 1) 207 { 208 VERBOSE(VB_IMPORTANT, LOC + 209 QString("DTS: nblks %1 not valid for normal frame") 210 .arg(*nblks)); 211 return -1; 212 } 213 214 return fsize; 215 } 216 217 static int dts_syncinfo(uint8_t *indata_ptr, int * /*flags*/, 218 int *sample_rate, int *bit_rate) 219 { 220 int nblks; 221 int rate; 222 int sfreq; 223 224 int fsize = dts_decode_header(indata_ptr, &rate, &nblks, &sfreq); 225 if (fsize >= 0) 226 { 227 if (rate >= 0 && rate <= 29) 228 *bit_rate = DTS_BITRATES[rate]; 229 else 230 *bit_rate = 0; 231 if (sfreq >= 1 && sfreq <= 15) 232 *sample_rate = DTS_SAMPLEFREQS[sfreq]; 233 else 234 *sample_rate = 0; 235 } 236 return fsize; 237 } 238 239 static int encode_frame( 240 bool dts, 241 unsigned char *data, 242 size_t &len) 243 { 244 size_t enc_len; 245 int flags, sample_rate, bit_rate; 246 247 // we don't do any length/crc validation of the AC3 frame here; presumably 248 // the receiver will have enough sense to do that. if someone has a 249 // receiver that doesn't, here would be a good place to put in a call 250 // to a52_crc16_block(samples+2, data_size-2) - but what do we do if the 251 // packet is bad? we'd need to send something that the receiver would 252 // ignore, and if so, may as well just assume that it will ignore 253 // anything with a bad CRC... 254 255 uint nr_samples = 0, block_len; 256 if (dts) 257 { 258 enc_len = dts_syncinfo(data+8, &flags, &sample_rate, &bit_rate); 259 int rate, sfreq, nblks; 260 dts_decode_header(data+8, &rate, &nblks, &sfreq); 261 nr_samples = nblks * 32; 262 block_len = nr_samples * 2 * 2; 263 } 264 else 265 { 266 enc_len = a52_syncinfo(data+8, &flags, &sample_rate, &bit_rate); 267 block_len = MAX_AC3_FRAME_SIZE; 268 } 269 270 if (enc_len == 0 || enc_len > len) 271 { 272 int l = len; 273 len = 0; 274 return l; 275 } 276 277 enc_len = min((uint)enc_len, block_len - 8); 278 279 //uint32_t x = *(uint32_t*)(data+8); 280 // in place swab 281 swab(data+8, data+8, enc_len); 282 //VERBOSE(VB_AUDIO|VB_TIMESTAMP, 283 // QString("DigitalEncoder::Encode swab test %1 %2") 284 // .arg(x,0,16).arg(*(uint32_t*)(data+8),0,16)); 285 286 // the following values come from libmpcodecs/ad_hwac3.c in mplayer. 287 // they form a valid IEC958 AC3 header. 288 data[0] = 0x72; 289 data[1] = 0xF8; 290 data[2] = 0x1F; 291 data[3] = 0x4E; 292 data[4] = 0x01; 293 if (dts) 294 { 295 switch(nr_samples) 296 { 297 case 512: 298 data[4] = 0x0B; /* DTS-1 (512-sample bursts) */ 299 break; 300 301 case 1024: 302 data[4] = 0x0C; /* DTS-2 (1024-sample bursts) */ 303 break; 304 305 case 2048: 306 data[4] = 0x0D; /* DTS-3 (2048-sample bursts) */ 307 break; 308 309 default: 310 VERBOSE(VB_IMPORTANT, LOC + 311 QString("DTS: %1-sample bursts not supported") 312 .arg(nr_samples)); 313 data[4] = 0x00; 314 break; 315 } 316 } 317 data[5] = 0x00; 318 data[6] = (enc_len << 3) & 0xFF; 319 data[7] = (enc_len >> 5) & 0xFF; 320 memset(data + 8 + enc_len, 0, block_len - 8 - enc_len); 321 len = block_len; 322 323 return enc_len; 324 } 325 326 // must have exactly 1 frames worth of data 327 size_t DigitalEncoder::Encode(short * buff) 328 { 329 int encsize = 0; 330 size_t outsize = 0; 331 332 // put data in the correct spot for encode frame 333 outsize = avcodec_encode_audio( 334 av_context, 335 ((uchar*)outbuf)+8, 336 outbuf_size-8, 337 buff); 338 size_t tmpsize = outsize; 339 340 outsize = MAX_AC3_FRAME_SIZE; 341 encsize = encode_frame( 342 //av_context->codec_id==CODEC_ID_DTS, 343 false, 344 (unsigned char*)outbuf, outsize); 345 VERBOSE(VB_AUDIO|VB_TIMESTAMP, 346 QString("DigitalEncoder::Encode len1=%1 len2=%2 finallen=%3") 347 .arg(tmpsize) 348 .arg(encsize) 349 .arg(outsize) 350 ); 351 352 return outsize; 353 } 354 #undef LOC 355 #define LOC QString("AO: ") 356 19 357 AudioOutputBase::AudioOutputBase( 20 358 QString laudio_main_device, QString laudio_passthru_device, 21 359 int /*laudio_bits*/, int /*laudio_channels*/, 22 360 int /*laudio_samplerate*/, AudioOutputSource lsource, 23 361 bool lset_initial_vol, bool /*laudio_passthru*/) : 24 25 362 effdsp(0), effdspstretched(0), 26 363 audio_channels(-1), audio_bytes_per_sample(0), 27 364 audio_bits(-1), audio_samplerate(-1), … … 32 369 audio_passthru_device(QDeepCopy<QString>(laudio_passthru_device)), 33 370 audio_passthru(false), audio_stretchfactor(1.0f), 34 371 372 audio_codec(NULL), 35 373 source(lsource), killaudio(false), 36 374 37 375 pauseaudio(false), audio_actually_paused(false), … … 58 396 pthread_cond_init(&audio_bufsig, NULL); 59 397 60 398 output_audio = 0; // TODO FIXME Not POSIX compatible! 399 configured_audio_channels = gContext->GetNumSetting("MaxChannels", 2); 61 400 62 401 bzero(&src_data, sizeof(SRC_DATA)); 63 402 bzero(src_in, sizeof(float) * AUDIO_SRC_IN_SIZE); … … 105 444 VERBOSE(VB_GENERAL, QString("Using time stretch %1") 106 445 .arg(audio_stretchfactor)); 107 446 pSoundStretch = new soundtouch::SoundTouch(); 108 pSoundStretch->setSampleRate(audio_samplerate); 109 pSoundStretch->setChannels(audio_channels); 447 if (audio_codec) 448 { 449 if (!encoder) 450 { 451 VERBOSE(VB_AUDIO, LOC + QString("Creating Encoder for codec %1 origfs %2").arg(audio_codec->codec_id).arg(audio_codec->frame_size)); 452 encoder = new DigitalEncoder(); 453 if (!encoder->Init(audio_codec->codec_id, 454 audio_codec->bit_rate, 455 audio_codec->sample_rate, 456 audio_codec->channels 457 )) 458 { 459 // eeks 460 delete encoder; 461 encoder = NULL; 462 VERBOSE(VB_AUDIO, LOC + QString("Failed to Create Encoder")); 463 } 464 } 465 } 466 if (encoder) 467 { 468 pSoundStretch->setSampleRate(audio_codec->sample_rate); 469 pSoundStretch->setChannels(audio_codec->channels); 470 } 471 else 472 { 473 pSoundStretch->setSampleRate(audio_samplerate); 474 pSoundStretch->setChannels(audio_channels); 475 } 110 476 111 477 pSoundStretch->setTempo(audio_stretchfactor); 112 478 pSoundStretch->setSetting(SETTING_SEQUENCE_MS, 35); … … 129 495 } 130 496 131 497 void AudioOutputBase::Reconfigure(int laudio_bits, int laudio_channels, 132 int laudio_samplerate, bool laudio_passthru) 498 int laudio_samplerate, bool laudio_passthru, 499 void* laudio_codec) 133 500 { 501 int codec_id = CODEC_ID_NONE; 502 int lcodec_id = CODEC_ID_NONE; 503 int lcchannels = 0; 504 int cchannels = 0; 505 if (laudio_codec) 506 { 507 lcodec_id = ((AVCodecContext*)laudio_codec)->codec_id; 508 laudio_bits = 16; 509 laudio_channels = 2; 510 laudio_samplerate = 48000; 511 lcchannels = ((AVCodecContext*)laudio_codec)->channels; 512 } 513 if (audio_codec) 514 { 515 codec_id = audio_codec->codec_id; 516 cchannels = ((AVCodecContext*)audio_codec)->channels; 517 } 518 ClearError(); 134 519 if (laudio_bits == audio_bits && laudio_channels == audio_channels && 135 laudio_samplerate == audio_samplerate && 136 laudio_passthru == audio_passthru && !need_resampler) 520 laudio_samplerate == audio_samplerate && !need_resampler && 521 laudio_passthru == audio_passthru && 522 lcodec_id == codec_id && lcchannels == cchannels) 137 523 return; 138 524 139 525 KillAudio(); … … 145 531 waud = raud = 0; 146 532 audio_actually_paused = false; 147 533 534 bool redo_stretch = (pSoundStretch && audio_channels != laudio_channels); 148 535 audio_channels = laudio_channels; 149 536 audio_bits = laudio_bits; 150 537 audio_samplerate = laudio_samplerate; 538 audio_codec = (AVCodecContext*)laudio_codec; 151 539 audio_passthru = laudio_passthru; 152 540 if (audio_bits != 8 && audio_bits != 16) 153 541 { … … 166 554 167 555 numlowbuffer = 0; 168 556 557 VERBOSE(VB_GENERAL, QString("Opening audio device '%1'. ch %2 sr %3") 558 .arg(audio_main_device).arg(audio_channels).arg(audio_samplerate)); 559 169 560 // Actually do the device specific open call 170 561 if (!OpenDevice()) 171 562 { 172 VERBOSE(VB_AUDIO, "Aborting reconfigure");173 563 pthread_mutex_unlock(&avsync_lock); 174 564 pthread_mutex_unlock(&audio_buflock); 565 if (GetError().isEmpty()) 566 Error("Aborting reconfigure"); 567 VERBOSE(VB_AUDIO, "Aborting reconfigure"); 175 568 return; 176 569 } 177 570 … … 194 587 current_seconds = -1; 195 588 source_bitrate = -1; 196 589 590 // NOTE: this wont do anything as above samplerate vars are set equal 197 591 // Check if we need the resampler 198 592 if (audio_samplerate != laudio_samplerate) 199 593 { … … 217 611 } 218 612 219 613 VERBOSE(VB_AUDIO, QString("Audio Stretch Factor: %1").arg(audio_stretchfactor)); 614 VERBOSE(VB_AUDIO, QString("Audio Codec Used: %1") 615 .arg(audio_codec?codec_id_string(audio_codec->codec_id):"not set")); 220 616 221 SetStretchFactorLocked(audio_stretchfactor); 222 if (pSoundStretch) 617 if (redo_stretch) 223 618 { 224 pSoundStretch->setSampleRate(audio_samplerate); 225 pSoundStretch->setChannels(audio_channels); 619 float laudio_stretchfactor = audio_stretchfactor; 620 delete pSoundStretch; 621 pSoundStretch = NULL; 622 audio_stretchfactor = 0.0; 623 SetStretchFactorLocked(laudio_stretchfactor); 226 624 } 625 else 626 { 627 SetStretchFactorLocked(audio_stretchfactor); 628 if (pSoundStretch) 629 { 630 // if its passthru then we need to reencode 631 if (audio_codec) 632 { 633 if (!encoder) 634 { 635 VERBOSE(VB_AUDIO, LOC + QString("Creating Encoder for codec %1").arg(audio_codec->codec_id)); 636 encoder = new DigitalEncoder(); 637 if (!encoder->Init(audio_codec->codec_id, 638 audio_codec->bit_rate, 639 audio_codec->sample_rate, 640 audio_codec->channels 641 )) 642 { 643 // eeks 644 delete encoder; 645 encoder = NULL; 646 VERBOSE(VB_AUDIO, LOC + QString("Failed to Create Encoder")); 647 } 648 } 649 } 650 if (encoder) 651 { 652 pSoundStretch->setSampleRate(audio_codec->sample_rate); 653 pSoundStretch->setChannels(audio_codec->channels); 654 } 655 else 656 { 657 pSoundStretch->setSampleRate(audio_samplerate); 658 pSoundStretch->setChannels(audio_channels); 659 } 660 } 661 } 227 662 228 663 // Setup visualisations, zero the visualisations buffers 229 664 prepareVisuals(); … … 269 704 pSoundStretch = NULL; 270 705 } 271 706 707 if (encoder) 708 { 709 delete encoder; 710 encoder = NULL; 711 } 712 272 713 CloseDevice(); 273 714 274 715 killAudioLock.unlock(); … … 282 723 283 724 void AudioOutputBase::Pause(bool paused) 284 725 { 726 VERBOSE(VB_AUDIO, LOC+ QString("Pause %0").arg(paused)); 285 727 pauseaudio = paused; 286 728 audio_actually_paused = false; 287 729 } … … 364 806 The reason is that computing 'audiotime' requires acquiring the audio 365 807 lock, which the video thread should not do. So, we call 'SetAudioTime()' 366 808 from the audio thread, and then call this from the video thread. */ 367 intret;809 long long ret; 368 810 struct timeval now; 369 811 370 812 if (audiotime == 0) … … 376 818 377 819 ret = (now.tv_sec - audiotime_updated.tv_sec) * 1000; 378 820 ret += (now.tv_usec - audiotime_updated.tv_usec) / 1000; 379 ret = ( int)(ret * audio_stretchfactor);821 ret = (long long)(ret * audio_stretchfactor); 380 822 823 #if 1 824 VERBOSE(VB_AUDIO|VB_TIMESTAMP, 825 QString("GetAudiotime now=%1.%2, set=%3.%4, ret=%5, audt=%6 sf=%7") 826 .arg(now.tv_sec).arg(now.tv_usec) 827 .arg(audiotime_updated.tv_sec).arg(audiotime_updated.tv_usec) 828 .arg(ret) 829 .arg(audiotime) 830 .arg(audio_stretchfactor) 831 ); 832 #endif 833 381 834 ret += audiotime; 382 835 383 836 pthread_mutex_unlock(&avsync_lock); 384 return ret;837 return (int)ret; 385 838 } 386 839 387 840 void AudioOutputBase::SetAudiotime(void) … … 418 871 // include algorithmic latencies 419 872 if (pSoundStretch) 420 873 { 874 // if encoder is active, then use its idea of audiobytes 875 //size_t abps = encoder?encoder->audio_bytes_per_sample:audio_bytes_per_sample; 876 877 // add the effect of any unused but processed samples, AC3 reencode does this 878 totalbuffer += (int)(pSoundStretch->numSamples() * audio_bytes_per_sample); 421 879 // add the effect of unprocessed samples in time stretch algo 422 880 totalbuffer += (int)((pSoundStretch->numUnprocessedSamples() * 423 881 audio_bytes_per_sample) / audio_stretchfactor); 424 882 } 425 883 426 884 audiotime = audbuf_timecode - (int)(totalbuffer * 100000.0 / 427 885 (audio_bytes_per_sample * effdspstretched)); 428 886 429 887 gettimeofday(&audiotime_updated, NULL); 888 #if 1 889 VERBOSE(VB_AUDIO|VB_TIMESTAMP, 890 QString("SetAudiotime set=%1.%2, audt=%3 atc=%4 tb=%5 sb=%6 eds=%7 abps=%8 sf=%9") 891 .arg(audiotime_updated.tv_sec).arg(audiotime_updated.tv_usec) 892 .arg(audiotime) 893 .arg(audbuf_timecode) 894 .arg(totalbuffer) 895 .arg(soundcard_buffer) 896 .arg(effdspstretched) 897 .arg(audio_bytes_per_sample) 898 .arg(audio_stretchfactor) 899 ); 900 #endif 430 901 431 902 pthread_mutex_unlock(&avsync_lock); 432 903 pthread_mutex_unlock(&audio_buflock); … … 486 957 // NOTE: This function is not threadsafe 487 958 488 959 int afree = audiofree(true); 489 int len = samples * audio_bytes_per_sample;960 int len = samples * (encoder?encoder->audio_bytes_per_sample:audio_bytes_per_sample); 490 961 491 962 // Check we have enough space to write the data 492 963 if (need_resampler && src_ctx) 493 964 len = (int)ceilf(float(len) * src_data.src_ratio); 494 965 if ((len > afree) && !blocking) 966 { 967 VERBOSE(VB_AUDIO|VB_TIMESTAMP, QString("AddSamples FAILED bytes=%1, used=%2, free=%3, timecode=%4") 968 .arg(len) 969 .arg(AUDBUFSIZE-afree).arg(afree).arg(LONGLONGCONVERT timecode)); 495 970 return false; // would overflow 971 } 496 972 497 973 // resample input if necessary 498 974 if (need_resampler && src_ctx) … … 526 1002 527 1003 int AudioOutputBase::WaitForFreeSpace(int samples) 528 1004 { 529 int len = samples * audio_bytes_per_sample; 1005 int abps = encoder?encoder->audio_bytes_per_sample:audio_bytes_per_sample; 1006 int len = samples * abps; 530 1007 int afree = audiofree(false); 531 1008 532 1009 while (len > afree) 533 1010 { 534 1011 if (blocking) 535 1012 { 536 VERBOSE(VB_AUDIO , "Waiting for free space");1013 VERBOSE(VB_AUDIO|VB_TIMESTAMP, "Waiting for free space"); 537 1014 // wait for more space 538 1015 pthread_cond_wait(&audio_bufsig, &audio_buflock); 539 1016 afree = audiofree(false); 540 1017 } 541 1018 else 542 1019 { 543 VERBOSE(VB_IMPORTANT, "Audio buffer overflow, audio data lost!"); 544 samples = afree / audio_bytes_per_sample; 545 len = samples * audio_bytes_per_sample; 1020 VERBOSE(VB_IMPORTANT, 1021 QString("Audio buffer overflow, %1 audio samples lost!") 1022 .arg(samples-afree / abps)); 1023 samples = afree / abps; 1024 len = samples * abps; 546 1025 if (src_ctx) 547 1026 { 548 1027 int error = src_reset(src_ctx); … … 567 1046 568 1047 int afree = audiofree(false); 569 1048 570 VERBOSE(VB_AUDIO, QString("_AddSamples bytes=%1, used=%2, free=%3, timecode=%4") 571 .arg(samples * audio_bytes_per_sample) 572 .arg(AUDBUFSIZE-afree).arg(afree).arg((long)timecode)); 1049 int abps = encoder?encoder->audio_bytes_per_sample:audio_bytes_per_sample; 1050 VERBOSE(VB_AUDIO|VB_TIMESTAMP, QString("_AddSamples samples=%1 bytes=%2, used=%3, free=%4, timecode=%5") 1051 .arg(samples) 1052 .arg(samples * abps) 1053 .arg(AUDBUFSIZE-afree).arg(afree).arg(LONGLONGCONVERT timecode)); 573 1054 574 1055 len = WaitForFreeSpace(samples); 575 1056 … … 606 1087 607 1088 if (pSoundStretch) 608 1089 { 1090 609 1091 // does not change the timecode, only the number of samples 610 1092 // back to orig pos 611 1093 org_waud = waud; 612 1094 int bdiff = AUDBUFSIZE - org_waud; 613 int nSamplesToEnd = bdiff/a udio_bytes_per_sample;1095 int nSamplesToEnd = bdiff/abps; 614 1096 if (bdiff < len) 615 1097 { 616 1098 pSoundStretch->putSamples((soundtouch::SAMPLETYPE*)(audiobuffer + 617 1099 org_waud), nSamplesToEnd); 618 1100 pSoundStretch->putSamples((soundtouch::SAMPLETYPE*)audiobuffer, 619 (len - bdiff) / a udio_bytes_per_sample);1101 (len - bdiff) / abps); 620 1102 } 621 1103 else 622 1104 { 623 1105 pSoundStretch->putSamples((soundtouch::SAMPLETYPE*)(audiobuffer + 624 org_waud), len / a udio_bytes_per_sample);1106 org_waud), len / abps); 625 1107 } 626 1108 627 int newLen = 0; 628 int nSamples; 629 len = WaitForFreeSpace(pSoundStretch->numSamples() * 630 audio_bytes_per_sample); 631 do 1109 if (encoder) 632 1110 { 633 int samplesToGet = len/audio_bytes_per_sample; 634 if (samplesToGet > nSamplesToEnd) 1111 // pull out a packet's worth and reencode it until we dont have enough 1112 // for any more packets 1113 soundtouch::SAMPLETYPE* temp_buff = 1114 (soundtouch::SAMPLETYPE*)encoder->GetFrameBuffer(); 1115 size_t frameSize = encoder->FrameSize()/abps; 1116 VERBOSE(VB_AUDIO|VB_TIMESTAMP, 1117 QString("_AddSamples Enc sfs=%1 bfs=%2 sss=%3") 1118 .arg(frameSize) 1119 .arg(encoder->FrameSize()) 1120 .arg(pSoundStretch->numSamples()) 1121 ); 1122 // process the same number of samples as it creates a full encoded buffer 1123 // just like before 1124 while (pSoundStretch->numSamples() >= frameSize) 635 1125 { 636 samplesToGet = nSamplesToEnd; 1126 int got = pSoundStretch->receiveSamples(temp_buff, frameSize); 1127 int amount = encoder->Encode(temp_buff); 1128 VERBOSE(VB_AUDIO|VB_TIMESTAMP, 1129 QString("_AddSamples Enc bytes=%1 got=%2 left=%3") 1130 .arg(amount) 1131 .arg(got) 1132 .arg(pSoundStretch->numSamples()) 1133 ); 1134 if (amount == 0) 1135 continue; 1136 //len = WaitForFreeSpace(amount); 1137 char * ob = encoder->GetOutBuff(); 1138 if (amount >= bdiff) 1139 { 1140 memcpy(audiobuffer + org_waud, ob, bdiff); 1141 ob += bdiff; 1142 amount -= bdiff; 1143 org_waud = 0; 1144 } 1145 if (amount > 0) 1146 memcpy(audiobuffer + org_waud, ob, amount); 1147 bdiff = AUDBUFSIZE - amount; 1148 org_waud += amount; 637 1149 } 638 639 nSamples = pSoundStretch->receiveSamples((soundtouch::SAMPLETYPE*) 640 (audiobuffer + org_waud), samplesToGet); 641 if (nSamples == nSamplesToEnd) 1150 } 1151 else 1152 { 1153 int newLen = 0; 1154 int nSamples; 1155 len = WaitForFreeSpace(pSoundStretch->numSamples() * 1156 audio_bytes_per_sample); 1157 do 642 1158 { 643 org_waud = 0; 644 nSamplesToEnd = AUDBUFSIZE/audio_bytes_per_sample; 645 } 646 else 647 { 648 org_waud += nSamples * audio_bytes_per_sample; 649 nSamplesToEnd -= nSamples; 650 } 1159 int samplesToGet = len/audio_bytes_per_sample; 1160 if (samplesToGet > nSamplesToEnd) 1161 { 1162 samplesToGet = nSamplesToEnd; 1163 } 651 1164 652 newLen += nSamples * audio_bytes_per_sample; 653 len -= nSamples * audio_bytes_per_sample; 654 } while (nSamples > 0); 1165 nSamples = pSoundStretch->receiveSamples((soundtouch::SAMPLETYPE*) 1166 (audiobuffer + org_waud), samplesToGet); 1167 if (nSamples == nSamplesToEnd) 1168 { 1169 org_waud = 0; 1170 nSamplesToEnd = AUDBUFSIZE/audio_bytes_per_sample; 1171 } 1172 else 1173 { 1174 org_waud += nSamples * audio_bytes_per_sample; 1175 nSamplesToEnd -= nSamples; 1176 } 1177 1178 newLen += nSamples * audio_bytes_per_sample; 1179 len -= nSamples * audio_bytes_per_sample; 1180 } while (nSamples > 0); 1181 } 655 1182 } 656 1183 657 1184 waud = org_waud; … … 727 1254 space_on_soundcard = getSpaceOnSoundcard(); 728 1255 729 1256 if (space_on_soundcard != last_space_on_soundcard) { 730 VERBOSE(VB_AUDIO , QString("%1 bytes free on soundcard")1257 VERBOSE(VB_AUDIO|VB_TIMESTAMP, QString("%1 bytes free on soundcard") 731 1258 .arg(space_on_soundcard)); 732 1259 last_space_on_soundcard = space_on_soundcard; 733 1260 } … … 740 1267 WriteAudio(zeros, fragment_size); 741 1268 } else { 742 1269 // this should never happen now -dag 743 VERBOSE(VB_AUDIO ,1270 VERBOSE(VB_AUDIO|VB_TIMESTAMP, 744 1271 QString("waiting for space on soundcard " 745 1272 "to write zeros: have %1 need %2") 746 1273 .arg(space_on_soundcard).arg(fragment_size)); … … 776 1303 if (fragment_size > audiolen(true)) 777 1304 { 778 1305 if (audiolen(true) > 0) // only log if we're sending some audio 779 VERBOSE(VB_AUDIO ,1306 VERBOSE(VB_AUDIO|VB_TIMESTAMP, 780 1307 QString("audio waiting for buffer to fill: " 781 1308 "have %1 want %2") 782 1309 .arg(audiolen(true)).arg(fragment_size)); 783 1310 784 VERBOSE(VB_AUDIO, "Broadcasting free space avail");1311 //VERBOSE(VB_AUDIO|VB_TIMESTAMP, "Broadcasting free space avail"); 785 1312 pthread_mutex_lock(&audio_buflock); 786 1313 pthread_cond_broadcast(&audio_bufsig); 787 1314 pthread_mutex_unlock(&audio_buflock); … … 795 1322 if (fragment_size > space_on_soundcard) 796 1323 { 797 1324 if (space_on_soundcard != last_space_on_soundcard) { 798 VERBOSE(VB_AUDIO ,1325 VERBOSE(VB_AUDIO|VB_TIMESTAMP, 799 1326 QString("audio waiting for space on soundcard: " 800 1327 "have %1 need %2") 801 1328 .arg(space_on_soundcard).arg(fragment_size)); … … 857 1384 858 1385 /* update raud */ 859 1386 raud = (raud + fragment_size) % AUDBUFSIZE; 860 VERBOSE(VB_AUDIO, "Broadcasting free space avail");1387 //VERBOSE(VB_AUDIO|VB_TIMESTAMP, "Broadcasting free space avail"); 861 1388 pthread_cond_broadcast(&audio_bufsig); 862 1389 863 1390 written_size = fragment_size; -
libs/libmyth/audiooutputalsa.cpp
86 86 } 87 87 else 88 88 { 89 fragment_size = 6144; // nicely divisible by 2,4,6,8 channels @ 16-bits 90 buffer_time = 500000; // .5 seconds 89 //fragment_size = 6144; // nicely divisible by 2,4,6,8 channels @ 16-bits 90 //fragment_size = 3072*audio_channels; // nicely divisible by 2,4,6,8 channels @ 16-bits 91 fragment_size = (audio_bits * audio_channels * audio_samplerate) / (8*30); 92 buffer_time = 100000; // .5 seconds 91 93 period_time = buffer_time / 4; // 4 interrupts per buffer 92 94 } 93 95 … … 159 161 160 162 tmpbuf = aubuf; 161 163 162 VERBOSE(VB_AUDIO , QString("WriteAudio: Preparing %1 bytes (%2 frames)")164 VERBOSE(VB_AUDIO|VB_TIMESTAMP, QString("WriteAudio: Preparing %1 bytes (%2 frames)") 163 165 .arg(size).arg(frames)); 164 166 165 167 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); … … 2363 2395 #ifdef CONFIG_DTS 2364 2396 vgrp0->addChild(DTSPassThrough()); 2365 2397 #endif 2398 addChild(MaxAudioChannels()); 2366 2399 2367 2400 VerticalConfigurationGroup *vgrp1 = 2368 2401 new VerticalConfigurationGroup(false, false, true, true); -
programs/mythtranscode/transcode.cpp
46 46 47 47 // reconfigure sound out for new params 48 48 virtual void Reconfigure(int audio_bits, int audio_channels, 49 int audio_samplerate, bool audio_passthru) 49 int audio_samplerate, bool audio_passthru, 50 void * = NULL) 50 51 { 52 ClearError(); 51 53 (void)audio_samplerate; 52 54 bits = audio_bits; 53 55 channels = audio_channels; 54 56 bytes_per_sample = bits * channels / 8; 57 if (channels>2) 58 Error("Invalid channel count"); 55 59 } 56 60 57 61 // dsprate is in 100 * samples/second -
libs/libmythtv/avformatdecoder.h
241 241 bool allow_ac3_passthru; 242 242 bool allow_dts_passthru; 243 243 bool disable_passthru; 244 int max_channels; 244 245 245 246 AudioInfo audioIn; 246 247 AudioInfo audioOut; -
libs/libmythtv/avformatdecoder.cpp
44 44 #define MAX_AC3_FRAME_SIZE 6144 45 45 46 46 /** Set to zero to allow any number of AC3 channels. */ 47 #define MAXCHANNELSELECT 1 48 #if MAXCHANNELSELECT 49 #define MAX_OUTPUT_CHANNELS compiler error 50 #else 47 51 #define MAX_OUTPUT_CHANNELS 2 52 #endif 48 53 49 54 static int dts_syncinfo(uint8_t *indata_ptr, int *flags, 50 55 int *sample_rate, int *bit_rate); … … 299 304 #ifdef CONFIG_DTS 300 305 allow_dts_passthru = gContext->GetNumSetting("DTSPassThru", false); 301 306 #endif 307 max_channels = gContext->GetNumSetting("MaxChannels", 2); 302 308 303 309 audioIn.sample_size = -32; // force SetupAudioStream to run once 304 310 itv = GetNVP()->GetInteractiveTV(); … … 432 438 framesPlayed = lastKey; 433 439 framesRead = lastKey; 434 440 441 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") 442 .arg(desiredFrame) 443 .arg(fps) 444 .arg(ts) 445 .arg(discardFrames) 446 .arg(framesPlayed) 447 .arg(st->cur_dts) 448 .arg(adj_cur_dts) 449 .arg(newts) 450 .arg(frameseekadjust) 451 ); 452 435 453 int normalframes = desiredFrame - framesPlayed; 436 454 455 #if 0 456 if (!exactseeks) 457 normalframes = 0; 458 #endif 459 437 460 SeekReset(lastKey, normalframes, discardFrames, discardFrames); 438 461 439 462 if (discardFrames) … … 803 826 804 827 fmt->flags &= ~AVFMT_NOFILE; 805 828 829 #if 1 830 if ((m_playbackinfo) || livetv || watchingrecording) 831 { 832 const char *name = ic->av_class->item_name(ic); 833 VERBOSE(VB_GENERAL, QString("libavformat type %1").arg(name)); 834 } 835 #endif 836 837 //struct timeval one, two, res; 838 //gettimeofday(&one, NULL); 839 806 840 if (!ringBuffer->isDVD() && !livetv) 807 841 av_estimate_timings(ic); 808 842 … … 813 847 if (-1 == ret) 814 848 return ret; 815 849 850 // make sure its at the real start due to av_find_stream_info reading 851 ret = av_seek_frame(ic, -1, 0, AVSEEK_FLAG_BACKWARD); 852 if (ret < 0) 853 av_seek_frame(ic, -1, 0, AVSEEK_FLAG_BYTE); // reposition to start of stream 854 816 855 AutoSelectTracks(); // This is needed for transcoder 817 856 818 857 { … … 842 881 // If we don't have a position map, set up ffmpeg for seeking 843 882 if (!recordingHasPositionMap) 844 883 { 884 const char *name = ic->av_class->item_name(ic); 845 885 VERBOSE(VB_PLAYBACK, LOC + 846 "Recording has no position -- using libavformat seeking.");886 QString("Recording has no position -- using libavformat seeking. %1").arg(name)); 847 887 int64_t dur = ic->duration / (int64_t)AV_TIME_BASE; 848 888 849 889 if (dur > 0) … … 888 928 QString("Successfully opened decoder for file: " 889 929 "\"%1\". novideo(%2)").arg(filename).arg(novideo)); 890 930 931 // set initial position correctly 932 //DoFastForward(0, true); 933 891 934 // Return true if recording has position map 892 935 return recordingHasPositionMap; 893 936 } … … 1301 1344 <<") already open, leaving it alone."); 1302 1345 } 1303 1346 //assert(enc->codec_id); 1347 VERBOSE(VB_GENERAL, QString("AVFD: codec %1 has %2 channels").arg(codec_id_string(enc->codec_id)).arg(enc->channels)); 1348 #if 0 1349 if (enc->channels > 2) 1350 enc->channels = 2; 1351 #endif 1304 1352 1353 #if 0 1305 1354 // HACK BEGIN REALLY UGLY HACK FOR DTS PASSTHRU 1306 1355 if (enc->codec_id == CODEC_ID_DTS) 1307 1356 { … … 1310 1359 // enc->bit_rate = what??; 1311 1360 } 1312 1361 // HACK END REALLY UGLY HACK FOR DTS PASSTHRU 1362 #endif 1313 1363 1314 1364 bitrate += enc->bit_rate; 1315 1365 break; … … 1777 1827 { 1778 1828 long long startpos = pkt->pos; 1779 1829 1780 VERBOSE(VB_PLAYBACK , LOC +1830 VERBOSE(VB_PLAYBACK|VB_TIMESTAMP, LOC + 1781 1831 QString("positionMap[ %1 ] == %2.") 1782 1832 .arg(prevgoppos / keyframedist) 1783 1833 .arg((int)startpos)); … … 2569 2619 2570 2620 AVStream *curstream = ic->streams[pkt->stream_index]; 2571 2621 2622 #if 0 2623 VERBOSE(VB_PLAYBACK|VB_TIMESTAMP, LOC + QString("timecode pts:%1 dts:%2 codec:%3") 2624 .arg(pkt->pts) 2625 .arg(pkt->dts) 2626 .arg((curstream && curstream->codec)?curstream->codec->codec_type:-1) 2627 ); 2628 #endif 2629 2572 2630 if (pkt->dts != (int64_t)AV_NOPTS_VALUE) 2573 2631 pts = (long long)(av_q2d(curstream->time_base) * pkt->dts * 1000); 2574 2632 … … 2721 2779 if (!curstream->codec->channels) 2722 2780 { 2723 2781 QMutexLocker locker(&avcodeclock); 2782 #if MAXCHANNELSELECT 2783 VERBOSE(VB_IMPORTANT, LOC + QString("Setting channels to %1").arg(audioOut.channels)); 2784 curstream->codec->cqp = max_channels; 2785 curstream->codec->channels = audioOut.channels; 2786 #else 2724 2787 curstream->codec->channels = MAX_OUTPUT_CHANNELS; 2788 #endif 2725 2789 ret = avcodec_decode_audio( 2726 2790 curstream->codec, audioSamples, 2727 2791 &data_size, ptr, len); … … 2775 2839 { 2776 2840 AVCodecContext *ctx = curstream->codec; 2777 2841 2842 #if MAXCHANNELSELECT 2778 2843 if ((ctx->channels == 0) || 2844 (ctx->channels > audioOut.channels)) 2845 ctx->channels = audioOut.channels; 2846 #else 2847 if ((ctx->channels == 0) || 2779 2848 (ctx->channels > MAX_OUTPUT_CHANNELS)) 2780 2849 ctx->channels = MAX_OUTPUT_CHANNELS; 2850 #endif 2781 2851 2782 2852 ret = avcodec_decode_audio( 2783 2853 ctx, audioSamples, &data_size, ptr, len); … … 2814 2884 (curstream->codec->channels * 2) / 2815 2885 curstream->codec->sample_rate); 2816 2886 2887 VERBOSE(VB_PLAYBACK|VB_TIMESTAMP, LOC + QString("audio timecode %1 %2 %3 %4") 2888 .arg(pkt->pts) 2889 .arg(pkt->dts) 2890 .arg(temppts).arg(lastapts)); 2817 2891 GetNVP()->AddAudioData((char *)audioSamples, data_size, 2818 2892 temppts); 2819 2893 … … 2928 3002 else 2929 3003 temppts = lastvpts; 2930 3004 3005 VERBOSE(VB_PLAYBACK|VB_TIMESTAMP, LOC + QString("video timecode %1 %2 %3 %4") 3006 .arg(pkt->pts) 3007 .arg(pkt->dts) 3008 .arg(temppts).arg(lastvpts)); 2931 3009 /* XXX: Broken. 2932 3010 if (mpa_pic.qscale_table != NULL && mpa_pic.qstride > 0 && 2933 3011 context->height == picframe->height) … … 3077 3155 3078 3156 void AvFormatDecoder::SetDisablePassThrough(bool disable) 3079 3157 { 3158 #if MAXCHANNELSELECT 3159 // can only disable never reenable as once tiemstretch is on its on for the session 3160 if (disable_passthru) 3161 return; 3162 #endif 3080 3163 if (selectedTrack[kTrackTypeAudio].av_stream_index < 0) 3081 3164 { 3082 3165 disable_passthru = disable; 3083 3166 return; 3084 3167 } 3085 3168 3086 3169 if (disable != disable_passthru) 3087 3170 { 3088 3171 disable_passthru = disable; … … 3109 3192 AVCodecContext *codec_ctx = NULL; 3110 3193 AudioInfo old_in = audioIn; 3111 3194 AudioInfo old_out = audioOut; 3195 bool using_passthru = false; 3112 3196 3113 3197 if ((currentTrack[kTrackTypeAudio] >= 0) && 3114 3198 (selectedTrack[kTrackTypeAudio].av_stream_index <= ic->nb_streams) && … … 3117 3201 { 3118 3202 assert(curstream); 3119 3203 assert(curstream->codec); 3120 codec_ctx = curstream->codec; 3204 codec_ctx = curstream->codec; 3121 3205 bool do_ac3_passthru = (allow_ac3_passthru && !transcoding && 3122 !disable_passthru &&3123 3206 (codec_ctx->codec_id == CODEC_ID_AC3)); 3124 3207 bool do_dts_passthru = (allow_dts_passthru && !transcoding && 3125 !disable_passthru &&3126 3208 (codec_ctx->codec_id == CODEC_ID_DTS)); 3209 using_passthru = do_ac3_passthru || do_dts_passthru; 3127 3210 info = AudioInfo(codec_ctx->codec_id, 3128 3211 codec_ctx->sample_rate, codec_ctx->channels, 3129 do_ac3_passthru || do_dts_passthru);3212 using_passthru && !disable_passthru); 3130 3213 } 3131 3214 3132 3215 if (info == audioIn) 3133 3216 return false; // no change 3134 3217 3218 QString ptmsg = ""; 3219 if (using_passthru) 3220 { 3221 ptmsg = QString(" using passthru"); 3222 } 3135 3223 VERBOSE(VB_AUDIO, LOC + "Initializing audio parms from " + 3136 3224 QString("audio track #%1").arg(currentTrack[kTrackTypeAudio]+1)); 3137 3225 3138 3226 audioOut = audioIn = info; 3227 #if MAXCHANNELSELECT 3228 if (using_passthru) 3229 #else 3139 3230 if (audioIn.do_passthru) 3231 #endif 3140 3232 { 3141 3233 // A passthru stream looks like a 48KHz 2ch (@ 16bit) to the sound card 3142 audioOut.channels = 2; 3143 audioOut.sample_rate = 48000; 3144 audioOut.sample_size = 4; 3234 AudioInfo digInfo = audioOut; 3235 if (!disable_passthru) 3236 { 3237 digInfo.channels = 2; 3238 digInfo.sample_rate = 48000; 3239 digInfo.sample_size = 4; 3240 } 3241 if (audioOut.channels > max_channels) 3242 { 3243 audioOut.channels = max_channels; 3244 audioOut.sample_size = audioOut.channels * 2; 3245 codec_ctx->channels = audioOut.channels; 3246 } 3247 #if MAXCHANNELSELECT 3248 VERBOSE(VB_AUDIO, LOC + "Audio format changed digital passthrough " + 3249 QString("%1\n\t\t\tfrom %2 ; %3\n\t\t\tto %4 ; %5") 3250 .arg(digInfo.toString()) 3251 .arg(old_in.toString()).arg(old_out.toString()) 3252 .arg(audioIn.toString()).arg(audioOut.toString())); 3253 3254 if (digInfo.sample_rate > 0) 3255 GetNVP()->SetEffDsp(digInfo.sample_rate * 100); 3256 3257 //GetNVP()->SetAudioParams(audioOut.bps(), audioOut.channels, 3258 // audioOut.sample_rate); 3259 GetNVP()->SetAudioParams(digInfo.bps(), digInfo.channels, 3260 digInfo.sample_rate, audioIn.do_passthru); 3261 // allow the audio stuff to reencode 3262 GetNVP()->SetAudioCodec(codec_ctx); 3263 GetNVP()->ReinitAudio(); 3264 return true; 3265 #endif 3145 3266 } 3267 #if MAXCHANNELSELECT 3146 3268 else 3147 3269 { 3270 if (audioOut.channels > max_channels) 3271 { 3272 audioOut.channels = max_channels; 3273 audioOut.sample_size = audioOut.channels * 2; 3274 codec_ctx->channels = audioOut.channels; 3275 } 3276 } 3277 bool audiook; 3278 #if 0 3279 do 3280 { 3281 #endif 3282 #else 3283 else 3284 { 3148 3285 if (audioOut.channels > MAX_OUTPUT_CHANNELS) 3149 3286 { 3150 3287 audioOut.channels = MAX_OUTPUT_CHANNELS; … … 3152 3289 codec_ctx->channels = MAX_OUTPUT_CHANNELS; 3153 3290 } 3154 3291 } 3292 #endif 3155 3293 3156 3294 VERBOSE(VB_AUDIO, LOC + "Audio format changed " + 3157 3295 QString("\n\t\t\tfrom %1 ; %2\n\t\t\tto %3 ; %4") … … 3164 3302 GetNVP()->SetAudioParams(audioOut.bps(), audioOut.channels, 3165 3303 audioOut.sample_rate, 3166 3304 audioIn.do_passthru); 3167 GetNVP()->ReinitAudio(); 3305 // allow the audio stuff to reencode 3306 GetNVP()->SetAudioCodec(using_passthru?codec_ctx:NULL); 3307 QString errMsg = GetNVP()->ReinitAudio(); 3308 #if MAXCHANNELSELECT 3309 audiook = errMsg.isEmpty(); 3310 #if 0 3311 if (!audiook) 3312 { 3313 switch (audioOut.channels) 3314 { 3315 #if 0 3316 case 8: 3317 audioOut.channels = 6; 3318 break; 3319 #endif 3320 case 6: 3321 #if 0 3322 audioOut.channels = 5; 3323 break; 3324 case 5: 3325 audioOut.channels = 4; 3326 break; 3327 case 4: 3328 audioOut.channels = 3; 3329 break; 3330 case 3: 3331 #endif 3332 audioOut.channels = 2; 3333 break; 3334 #if 0 3335 case 2: 3336 audioOut.channels = 1; 3337 break; 3338 #endif 3339 default: 3340 // failed to reconfigure under any circumstances 3341 audiook = true; 3342 audioOut.channels = 0; 3343 break; 3344 } 3345 audioOut.sample_size = audioOut.channels * 2; 3346 codec_ctx->channels = audioOut.channels; 3347 } 3348 } while (!audiook); 3349 #endif 3350 #endif 3168 3351 3169 3352 return true; 3170 3353 } -
libs/libmythtv/NuppelVideoPlayer.h
123 123 void SetAudioInfo(const QString &main, const QString &passthru, uint rate); 124 124 void SetAudioParams(int bits, int channels, int samplerate, bool passthru); 125 125 void SetEffDsp(int dsprate); 126 void SetAudioCodec(void *ac); 126 127 127 128 // Sets 128 129 void SetParentWidget(QWidget *widget) { parentWidget = widget; } … … 196 197 bool IsDecoderThreadAlive(void) const { return decoder_thread_alive; } 197 198 bool IsReallyNearEnd(void) const; 198 199 bool IsNearEnd(long long framesRemaining = -1) const; 200 float GetAudioStretchFactor() { return audio_stretchfactor; } 199 201 bool PlayingSlowForPrebuffer(void) const { return m_playing_slower; } 200 202 bool HasAudioIn(void) const { return !no_audio_in; } 201 203 bool HasAudioOut(void) const { return !no_audio_out; } … … 226 228 bool Play(float speed = 1.0, bool normal = true, 227 229 bool unpauseaudio = true); 228 230 bool GetPause(void) const; 231 float GetNextPlaySpeed() { return next_play_speed; } 229 232 230 233 // Seek stuff 231 234 bool FastForward(float seconds); … … 659 662 int audio_bits; 660 663 int audio_samplerate; 661 664 float audio_stretchfactor; 665 void *audio_codec; 662 666 bool audio_passthru; 663 667 664 668 // Picture-in-Picture -
libs/libmythtv/NuppelVideoPlayer.cpp
202 202 audio_passthru_device(QString::null), 203 203 audio_channels(2), audio_bits(-1), 204 204 audio_samplerate(44100), audio_stretchfactor(1.0f), 205 audio_codec(NULL), 205 206 // Picture-in-Picture 206 207 pipplayer(NULL), setpipplayer(NULL), needsetpipplayer(false), 207 208 // Preview window support … … 681 682 if (audioOutput) 682 683 { 683 684 audioOutput->Reconfigure(audio_bits, audio_channels, 684 audio_samplerate, audio_passthru); 685 audio_samplerate, audio_passthru, 686 audio_codec); 685 687 errMsg = audioOutput->GetError(); 686 688 if (!errMsg.isEmpty()) 687 689 audioOutput->SetStretchFactor(audio_stretchfactor); … … 2009 2011 warpfactor_avg = (warpfactor + (warpfactor_avg * (WARPAVLEN - 1))) / 2010 2012 WARPAVLEN; 2011 2013 2012 //cerr << "Divergence: " << divergence << " Rate: " << rate 2013 //<< " Warpfactor: " << warpfactor << " warpfactor_avg: " 2014 //<< warpfactor_avg << endl; 2014 #if 1 2015 VERBOSE(VB_PLAYBACK|VB_TIMESTAMP, QString("A/V " 2016 "Divergence: %1 " 2017 " Rate: %2" 2018 " Warpfactor: %3" 2019 " warpfactor_avg: %4") 2020 .arg(divergence) 2021 .arg(rate) 2022 .arg(warpfactor) 2023 .arg(warpfactor_avg) 2024 ); 2025 #endif 2015 2026 return divergence; 2016 2027 } 2017 2028 … … 2110 2121 // decoding; display the frame, but don't wait for A/V Sync. 2111 2122 videoOutput->PrepareFrame(buffer, kScan_Intr2ndField); 2112 2123 videoOutput->Show(kScan_Intr2ndField); 2113 VERBOSE(VB_PLAYBACK , LOC + dbg + "skipping A/V wait.");2124 VERBOSE(VB_PLAYBACK|VB_TIMESTAMP, LOC + dbg + "skipping A/V wait."); 2114 2125 } 2115 2126 else 2116 2127 { 2117 2128 // If we are using software decoding, skip this frame altogether. 2129 //VERBOSE(VB_PLAYBACK|VB_TIMESTAMP, LOC + dbg + "dropping frame."); 2118 2130 VERBOSE(VB_PLAYBACK, LOC + dbg + "dropping frame to catch up."); 2119 2131 } 2120 2132 } … … 2124 2136 if (buffer) 2125 2137 videoOutput->PrepareFrame(buffer, ps); 2126 2138 2139 VERBOSE(VB_PLAYBACK|VB_TIMESTAMP, QString("AVSync waitforframe %1 %2").arg(avsync_adjustment).arg(m_double_framerate)); 2127 2140 videosync->WaitForFrame(avsync_adjustment); 2141 VERBOSE(VB_PLAYBACK|VB_TIMESTAMP, "AVSync show"); 2128 2142 if (!resetvideo) 2129 2143 videoOutput->Show(ps); 2130 2144 … … 2146 2160 2147 2161 // Display the second field 2148 2162 videosync->AdvanceTrigger(); 2149 videosync->WaitForFrame( 0);2163 videosync->WaitForFrame(avsync_adjustment); 2150 2164 if (!resetvideo) 2151 2165 { 2152 2166 videoOutput->Show(ps); … … 2160 2174 2161 2175 if (output_jmeter && output_jmeter->RecordCycleTime()) 2162 2176 { 2163 //cerr << "avsync_delay: " << avsync_delay / 1000 2164 // << ", avsync_avg: " << avsync_avg / 1000 2165 // << ", warpfactor: " << warpfactor 2166 // << ", warpfactor_avg: " << warpfactor_avg << endl; 2177 #if 1 2178 VERBOSE(VB_PLAYBACK|VB_TIMESTAMP, QString("A/V " 2179 "avsync_delay: %1" 2180 ", avsync_avg: %2" 2181 ", warpfactor: %3" 2182 ", warpfactor_avg: %4") 2183 .arg(avsync_delay / 1000) 2184 .arg(avsync_avg / 1000) 2185 .arg(warpfactor) 2186 .arg(warpfactor_avg)); 2187 #endif 2167 2188 } 2168 2189 2169 2190 videosync->AdvanceTrigger(); … … 2174 2195 // If audio is way behind of video, adjust for it... 2175 2196 // by cutting the frame rate in half for the length of this frame 2176 2197 2177 avsync_adjustment = frame_interval; 2198 //avsync_adjustment = frame_interval; 2199 avsync_adjustment = refreshrate; 2178 2200 lastsync = true; 2201 //VERBOSE(VB_PLAYBACK|VB_TIMESTAMP, LOC + 2202 // QString("Video is %1 frames ahead of audio,\n" 2203 // "\t\t\tdoubling video frame interval.").arg(diverge)); 2179 2204 VERBOSE(VB_PLAYBACK, LOC + 2180 2205 QString("Video is %1 frames ahead of audio,\n" 2181 2206 "\t\t\tdoubling video frame interval to slow down.").arg(diverge)); … … 2184 2209 if (audioOutput && normal_speed) 2185 2210 { 2186 2211 long long currentaudiotime = audioOutput->GetAudiotime(); 2187 #if 02188 VERBOSE(VB_PLAYBACK , QString(2212 #if 1 2213 VERBOSE(VB_PLAYBACK|VB_TIMESTAMP, QString( 2189 2214 "A/V timecodes audio %1 video %2 frameinterval %3 " 2190 2215 "avdel %4 avg %5 tcoffset %6") 2191 2216 .arg(currentaudiotime) … … 2509 2534 2510 2535 usevideotimebase = gContext->GetNumSetting("UseVideoTimebase", 0); 2511 2536 2512 if ((print_verbose_messages & VB_PLAYBACK ) != 0)2537 if ((print_verbose_messages & VB_PLAYBACK|VB_TIMESTAMP) == (VB_PLAYBACK|VB_TIMESTAMP)) 2513 2538 output_jmeter = new Jitterometer("video_output", 100); 2514 2539 else 2515 2540 output_jmeter = NULL; … … 2555 2580 { 2556 2581 VERBOSE(VB_IMPORTANT, "Video sync method can't support double " 2557 2582 "framerate (refresh rate too low for bob deint)"); 2583 //m_scan = kScan_Ignore; 2584 //m_can_double = false; 2558 2585 FallbackDeint(); 2559 2586 } 2560 2587 } … … 3397 3424 audio_passthru = passthru; 3398 3425 } 3399 3426 3427 void NuppelVideoPlayer::SetAudioCodec(void* ac) 3428 { 3429 audio_codec = ac; 3430 } 3431 3400 3432 void NuppelVideoPlayer::SetEffDsp(int dsprate) 3401 3433 { 3402 3434 if (audioOutput) … … 3441 3473 tc_avcheck_framecounter++; 3442 3474 if (tc_avcheck_framecounter == 30) 3443 3475 { 3444 #define AUTO_RESYNC 13476 #define AUTO_RESYNC 0 3445 3477 #if AUTO_RESYNC 3446 3478 // something's terribly, terribly wrong. 3447 3479 if (tc_lastval[TC_AUDIO] < tc_lastval[TC_VIDEO] - 10000000 || -
libs/libavcodec/a52dec.c
142 142 } 143 143 } 144 144 145 static inline int16_t convert (int32_t i) 146 { 147 if (i > 0x43c07fff) 148 return 32767; 149 else if (i < 0x43bf8000) 150 return -32768; 151 else 152 return i - 0x43c00000; 153 } 154 155 void float2s16_2 (float * _f, int16_t * s16) 156 { 157 int i; 158 int32_t * f = (int32_t *) _f; 159 160 for (i = 0; i < 256; i++) { 161 s16[2*i] = convert (f[i]); 162 s16[2*i+1] = convert (f[i+256]); 163 } 164 } 165 166 void float2s16_4 (float * _f, int16_t * s16) 167 { 168 int i; 169 int32_t * f = (int32_t *) _f; 170 171 for (i = 0; i < 256; i++) { 172 s16[4*i] = convert (f[i]); 173 s16[4*i+1] = convert (f[i+256]); 174 s16[4*i+2] = convert (f[i+512]); 175 s16[4*i+3] = convert (f[i+768]); 176 } 177 } 178 179 void float2s16_5 (float * _f, int16_t * s16) 180 { 181 int i; 182 int32_t * f = (int32_t *) _f; 183 184 for (i = 0; i < 256; i++) { 185 s16[5*i] = convert (f[i]); 186 s16[5*i+1] = convert (f[i+256]); 187 s16[5*i+2] = convert (f[i+512]); 188 s16[5*i+3] = convert (f[i+768]); 189 s16[5*i+4] = convert (f[i+1024]); 190 } 191 } 192 193 int channels_multi (int flags) 194 { 195 if (flags & A52_LFE) 196 return 6; 197 else if (flags & 1) /* center channel */ 198 return 5; 199 else if ((flags & A52_CHANNEL_MASK) == A52_2F2R) 200 return 4; 201 else 202 return 2; 203 } 204 205 void float2s16_multi (float * _f, int16_t * s16, int flags) 206 { 207 int i; 208 int32_t * f = (int32_t *) _f; 209 210 switch (flags) { 211 case A52_MONO: 212 for (i = 0; i < 256; i++) { 213 s16[5*i] = s16[5*i+1] = s16[5*i+2] = s16[5*i+3] = 0; 214 s16[5*i+4] = convert (f[i]); 215 } 216 break; 217 case A52_CHANNEL: 218 case A52_STEREO: 219 case A52_DOLBY: 220 float2s16_2 (_f, s16); 221 break; 222 case A52_3F: 223 for (i = 0; i < 256; i++) { 224 s16[5*i] = convert (f[i]); 225 s16[5*i+1] = convert (f[i+512]); 226 s16[5*i+2] = s16[5*i+3] = 0; 227 s16[5*i+4] = convert (f[i+256]); 228 } 229 break; 230 case A52_2F2R: 231 float2s16_4 (_f, s16); 232 break; 233 case A52_3F2R: 234 float2s16_5 (_f, s16); 235 break; 236 case A52_MONO | A52_LFE: 237 for (i = 0; i < 256; i++) { 238 s16[6*i] = s16[6*i+1] = s16[6*i+2] = s16[6*i+3] = 0; 239 s16[6*i+4] = convert (f[i+256]); 240 s16[6*i+5] = convert (f[i]); 241 } 242 break; 243 case A52_CHANNEL | A52_LFE: 244 case A52_STEREO | A52_LFE: 245 case A52_DOLBY | A52_LFE: 246 for (i = 0; i < 256; i++) { 247 s16[6*i] = convert (f[i+256]); 248 s16[6*i+1] = convert (f[i+512]); 249 s16[6*i+2] = s16[6*i+3] = s16[6*i+4] = 0; 250 s16[6*i+5] = convert (f[i]); 251 } 252 break; 253 case A52_3F | A52_LFE: 254 for (i = 0; i < 256; i++) { 255 s16[6*i] = convert (f[i+256]); 256 s16[6*i+1] = convert (f[i+768]); 257 s16[6*i+2] = s16[6*i+3] = 0; 258 s16[6*i+4] = convert (f[i+512]); 259 s16[6*i+5] = convert (f[i]); 260 } 261 break; 262 case A52_2F2R | A52_LFE: 263 for (i = 0; i < 256; i++) { 264 s16[6*i] = convert (f[i+256]); 265 s16[6*i+1] = convert (f[i+512]); 266 s16[6*i+2] = convert (f[i+768]); 267 s16[6*i+3] = convert (f[i+1024]); 268 s16[6*i+4] = 0; 269 s16[6*i+5] = convert (f[i]); 270 } 271 break; 272 case A52_3F2R | A52_LFE: 273 for (i = 0; i < 256; i++) { 274 s16[6*i] = convert (f[i+256]); 275 s16[6*i+1] = convert (f[i+768]); 276 s16[6*i+2] = convert (f[i+1024]); 277 s16[6*i+3] = convert (f[i+1280]); 278 s16[6*i+4] = convert (f[i+512]); 279 s16[6*i+5] = convert (f[i]); 280 } 281 break; 282 } 283 } 284 285 145 286 /**** end */ 146 287 147 288 #define HEADER_SIZE 7 … … 183 324 /* update codec info */ 184 325 avctx->sample_rate = sample_rate; 185 326 s->channels = ac3_channels[s->flags & 7]; 327 if (avctx->cqp >= 0) 328 avctx->channels = avctx->cqp; 186 329 if (s->flags & A52_LFE) 187 330 s->channels++; 188 331 if (avctx->channels == 0) … … 205 348 s->inbuf_ptr += len; 206 349 buf_size -= len; 207 350 } else { 351 int chans; 208 352 flags = s->flags; 209 353 if (avctx->channels == 1) 210 354 flags = A52_MONO; 211 else if (avctx->channels == 2) 212 flags = A52_STEREO; 355 else if (avctx->channels == 2) { 356 if (s->channels>2) 357 flags = A52_DOLBY; 358 else 359 flags = A52_STEREO; 360 } 213 361 else 214 362 flags |= A52_ADJUST_LEVEL; 215 363 level = 1; 364 chans = channels_multi(flags); 216 365 if (s->a52_frame(s->state, s->inbuf, &flags, &level, 384)) { 217 366 fail: 218 367 s->inbuf_ptr = s->inbuf; … … 222 371 for (i = 0; i < 6; i++) { 223 372 if (s->a52_block(s->state)) 224 373 goto fail; 225 float_to_int(s->samples, out_samples + i * 256 * avctx->channels, avctx->channels); 374 //float_to_int(s->samples, out_samples + i * 256 * avctx->channels, avctx->channels); 375 float2s16_multi(s->samples, out_samples + i * 256 * chans, flags); 226 376 } 227 377 s->inbuf_ptr = s->inbuf; 228 378 s->frame_size = 0; 229 *data_size = 6 * avctx->channels * 256 * sizeof(int16_t); 379 //*data_size = 6 * avctx->channels * 256 * sizeof(int16_t); 380 *data_size = 6 * chans * 256 * sizeof(int16_t); 230 381 break; 231 382 } 232 383 } -
libs/libavcodec/ac3enc.c
1336 1336 { 1337 1337 AC3EncodeContext *s = avctx->priv_data; 1338 1338 int16_t *samples = data; 1339 // expects L C R LS RS LFE 1340 // audio format is L R LS RS C LFE 1341 static int channel_index[6] = { 0, 4, 1, 2, 3, 5 }; 1342 /* 1343 * A52->Analog->AC3Enc 1344 * 1->0->0 1345 * 3->1->2 1346 * 4->2->3 1347 * 5->3->4 1348 * 2->4->1 1349 * 0->5->5 1350 */ 1339 1351 int i, j, k, v, ch; 1340 1352 int16_t input_samples[N]; 1341 1353 int32_t mdct_coef[NB_BLOCKS][AC3_MAX_CHANNELS][N/2]; … … 1356 1368 /* compute input samples */ 1357 1369 memcpy(input_samples, s->last_samples[ch], N/2 * sizeof(int16_t)); 1358 1370 sinc = s->nb_all_channels; 1359 sptr = samples + (sinc * (N/2) * i) + ch ;1371 sptr = samples + (sinc * (N/2) * i) + channel_index[ch]; 1360 1372 for(j=0;j<N/2;j++) { 1361 1373 v = *sptr; 1362 1374 input_samples[j + N/2] = v;