#include <filehandler.h>
Inheritance diagram for AVIHandler:


Public Member Functions | |
| AVIHandler (int format=AVI_DV1_FORMAT) | |
| ~AVIHandler () | |
| void | SetSampleFrame (const Frame &sample) |
| bool | FileIsOpen () |
| bool | Create (const string &filename) |
| int | Write (const Frame &frame) |
| int | Close () |
| off_t | GetFileSize () |
| int | GetTotalFrames () |
| bool | Open (const char *s) |
| int | GetFrame (Frame &frame, int frameNum) |
| int16_t * | SeekAudioFrame (Frame &frame, int frameNum, int &availableSize) |
| bool | GetOpenDML () const |
| void | SetOpenDML (bool) |
| int | GetFormat () const |
Protected Attributes | |
| AVIFile * | avi |
| int | aviFormat |
| AudioInfo | audioInfo |
| VideoInfo | videoInfo |
| bool | isOpenDML |
| DVINFO | dvinfo |
| FOURCC | fccHandler |
| int | channels |
| bool | isFullyInitialized |
| int16_t * | audioBuffer |
| int16_t * | audioChannels [4] |
| bool | isInterleave1to1 |
| off_t | audioOffset |
| int | audioBufferSize |
|
|
Definition at line 428 of file filehandler.cc. References audioChannels, and FileHandler::extension. 00428 : avi( NULL ), aviFormat( format ), isOpenDML( false ), 00429 fccHandler( make_fourcc( "dvsd" ) ), channels( 2 ), isFullyInitialized( false ), 00430 audioBuffer( NULL ), isInterleave1to1( true ) 00431 { 00432 extension = ".avi"; 00433 for ( int c = 0; c < 4; c++ ) 00434 audioChannels[ c ] = NULL; 00435 }
|
|
|
Definition at line 438 of file filehandler.cc. References audioBuffer, audioChannels, and avi. 00439 {
00440 if ( audioBuffer != NULL )
00441 {
00442 delete[] audioBuffer;
00443 audioBuffer = NULL;
00444 }
00445 for ( int c = 0; c < 4; c++ )
00446 {
00447 if ( audioChannels[ c ] != NULL )
00448 {
00449 delete[] audioChannels[ c ];
00450 audioChannels[ c ] = NULL;
00451 }
00452 }
00453
00454 delete avi;
00455 }
|
|
|
Implements FileHandler. Definition at line 545 of file filehandler.cc. References audioBuffer, audioChannels, avi, isFullyInitialized, and AVIFile::WriteRIFF(). 00546 {
00547 if ( avi != NULL )
00548 {
00549 avi->WriteRIFF();
00550 delete avi;
00551 avi = NULL;
00552 }
00553 if ( audioBuffer != NULL )
00554 {
00555 delete audioBuffer;
00556 audioBuffer = NULL;
00557 }
00558 for ( int c = 0; c < 4; c++ )
00559 {
00560 if ( audioChannels[ c ] != NULL )
00561 {
00562 delete audioChannels[ c ];
00563 audioChannels[ c ] = NULL;
00564 }
00565 }
00566 isFullyInitialized = false;
00567 return 0;
00568 }
|
|
|
|
Implements FileHandler. Definition at line 485 of file filehandler.cc. References avi. 00486 {
00487 return avi != NULL;
00488 }
|
|
|
Implements FileHandler. Definition at line 570 of file filehandler.cc. References avi, and RIFFFile::GetFileSize(). 00571 {
00572 return avi->GetFileSize();
00573 }
|
|
|
Definition at line 158 of file filehandler.h. References aviFormat. Referenced by KinoCommon::showFrameMoreInfo(). 00159 {
00160 return aviFormat;
00161 }
|
|
||||||||||||
|
Implements FileHandler. Definition at line 619 of file filehandler.cc. References audioBuffer, audioChannels, audioInfo, avi, AVI_AUDIO_BUFFER_SECS, AVI_DV2_FORMAT, aviFormat, AudioInfo::channels, channels, DV_AUDIO_MAX_SAMPLES, FOURCC, AudioInfo::frequency, AVIFile::GetDVFrame(), AVIFile::getFrame(), AVIFile::getStreamFormat(), isFullyInitialized, isInterleave1to1, make_fourcc(), AudioInfo::samples, and SeekAudioFrame(). 00620 {
00621 int result = avi->GetDVFrame( frame, frameNum );
00622 if ( result == 0 )
00623 {
00624 /* get the audio from the audio stream, if available */
00625 if ( aviFormat == AVI_DV2_FORMAT )
00626 {
00627 WAVEFORMATEX wav;
00628 FOURCC fccWav = make_fourcc( "01wb" );
00629
00630 if ( ! isFullyInitialized &&
00631 avi->getStreamFormat( ( void* ) &wav, make_fourcc( "auds" ) ) )
00632 {
00633 if ( channels > 0 && channels < 5 )
00634 {
00635 // Allocate interleaved audio buffer to accomodate large chunks
00636 audioBuffer = new int16_t[ wav.nSamplesPerSec * channels * AVI_AUDIO_BUFFER_SECS ];
00637
00638 // Allocate non-interleaved audio buffers
00639 for ( int c = 0; c < channels; c++ )
00640 audioChannels[ c ] = new int16_t[ 2 * DV_AUDIO_MAX_SAMPLES ];
00641
00642 // Get the audio parameters from AVI for subsequent calls to method
00643 audioInfo.channels = wav.nChannels;
00644 audioInfo.frequency = wav.nSamplesPerSec;
00645
00646 // Skip initialization on subsequent calls to method
00647 isFullyInitialized = true;
00648 cerr << ">>> using audio from separate AVI audio stream" << endl;
00649 }
00650 }
00651
00652 // Get the frame from AVI
00653 if ( isInterleave1to1 )
00654 {
00655 int n = avi->getFrame( audioBuffer, frameNum, fccWav );
00656 if ( n > 0 )
00657 {
00658 // Temporary pointer to audio scratch buffer
00659 int16_t * s = audioBuffer;
00660
00661 // Determine samples in this frame
00662 audioInfo.samples = n / audioInfo.channels / sizeof( int16_t );
00663 if ( audioInfo.samples > DV_AUDIO_MAX_SAMPLES )
00664 audioInfo.samples = DV_AUDIO_MAX_SAMPLES;
00665
00666 // Convert interleaved audio into non-interleaved
00667 for ( int n = 0; n < audioInfo.samples; ++n )
00668 for ( int i = 0; i < audioInfo.channels; i++ )
00669 audioChannels[ i ][ n ] = *s++;
00670 }
00671 }
00672 else
00673 {
00674 int16_t* s;
00675 int availSamples = 0;
00676
00677 // Fetch correct audio chunk and get audio buffer offset
00678 if ( ( s = SeekAudioFrame( frame, frameNum, availSamples ) ) )
00679 {
00680 if ( availSamples < audioInfo.samples )
00681 {
00682 // Not enough samples in audio buffer
00683 int n;
00684
00685 // Convert interleaved samples remaining in the buffer
00686 for ( n = 0; n < availSamples; ++n )
00687 for ( int i = 0; i < audioInfo.channels; i++ )
00688 audioChannels[ i ][ n ] = *s++;
00689
00690 // Load the next audio chunk into buffer
00691 if ( ( s = SeekAudioFrame( frame, frameNum + 1, availSamples ) ) )
00692 {
00693 // Convert interleaved audio into non-interleaved
00694 for ( --n; n < audioInfo.samples; ++n )
00695 for ( int i = 0; i < audioInfo.channels; i++ )
00696 audioChannels[ i ][ n ] = *s++;
00697 }
00698 else if ( availSamples >= 0 )
00699 {
00700 // Just truncate number of samples in this frame
00701 audioInfo.samples = availSamples;
00702 }
00703 }
00704 else
00705 {
00706 // Convert interleaved audio into non-interleaved
00707 for ( int n = 0; n < audioInfo.samples; ++n )
00708 for ( int i = 0; i < audioInfo.channels; i++ )
00709 audioChannels[ i ][ n ] = *s++;
00710 }
00711 }
00712 // <0 signals an error in SeekAudioFrame
00713 if ( availSamples < 0 )
00714 return result;
00715 }
00716 // Write interleaved audio into frame
00717 frame.EncodeAudio( audioInfo, audioChannels );
00718 }
00719 // Parse important metadata in DV bitstream
00720 frame.ExtractHeader();
00721 }
00722 return result;
00723 }
|
|
|
Definition at line 774 of file filehandler.cc. References isOpenDML. Referenced by Create(), and KinoCommon::showFrameMoreInfo(). 00775 {
00776 return isOpenDML;
00777 }
|
|
|
Implements FileHandler. Definition at line 575 of file filehandler.cc. References avi, and AVIFile::GetTotalFrames(). 00576 {
00577 return avi->GetTotalFrames();
00578 }
|
|
|
||||||||||||||||
|
Definition at line 726 of file filehandler.cc. References audioBuffer, audioBufferSize, audioInfo, audioOffset, avi, AVI_AUDIO_BUFFER_SECS, AudioInfo::channels, FOURCC, AudioInfo::frequency, AVIFile::getFrame(), AVIFile::GetFrameInfo(), make_fourcc(), and AudioInfo::samples. Referenced by GetFrame(). 00727 {
00728 // Not very optimized - needs to seek to PCM sample offset
00729 FOURCC fccWav = make_fourcc( "01wb" );
00730 frame.ExtractHeader();
00731 off_t offsetBytes = off_t( 0.5 + (float) frameNum / frame.GetFrameRate() * audioInfo.frequency );
00732 offsetBytes *= audioInfo.channels * sizeof(int16_t);
00733
00734 // If cache miss
00735 if ( offsetBytes < audioOffset || offsetBytes >= ( audioOffset + audioBufferSize ) )
00736 {
00737 int i = 0;
00738 off_t dummy;
00739
00740 // Find chunk corresponding to offset
00741 for ( audioOffset = 0; avi->GetFrameInfo( dummy, audioBufferSize, i, fccWav ) != -1; ++i )
00742 {
00743 if ( audioBufferSize <= 0 )
00744 {
00745 availableSize = -1;
00746 return 0;
00747 }
00748 if ( audioOffset + audioBufferSize > offsetBytes )
00749 break;
00750 audioOffset += audioBufferSize;
00751 }
00752 // Read chunk if buffer is large enough to hold it
00753 if ( audioBufferSize > ( off_t( audioInfo.frequency ) * audioInfo.channels * sizeof(int16_t) * AVI_AUDIO_BUFFER_SECS ) ||
00754 !avi->getFrame( audioBuffer, i, fccWav ) )
00755 {
00756 return 0;
00757 }
00758 }
00759 // Return how many samples in buffer are available after seeking
00760 availableSize = ( audioBufferSize - int( offsetBytes - audioOffset ) ) >> 2;
00761 // Set number of samples to use in this frame
00762 audioInfo.samples = frame.CalculateNumberSamples( audioInfo.frequency, frameNum );
00763 // Return offset into audio buffer
00764 return audioBuffer + ( ( offsetBytes - audioOffset ) >> 1 );
00765 }
|
|
|
Definition at line 768 of file filehandler.cc. References isOpenDML. Referenced by ExportAVI::doExport(), and PageCapture::startCapture(). 00769 {
00770 isOpenDML = flag;
00771 }
|
|
|
Reimplemented from FileHandler. Definition at line 457 of file filehandler.cc. References audioInfo, Pack::data, dvinfo, DWORD, fccHandler, make_fourcc(), and videoInfo. 00458 {
00459 Pack pack;
00460 sample.GetAudioInfo( audioInfo );
00461 sample.GetVideoInfo( videoInfo );
00462
00463 sample.GetAAUXPack( 0x50, pack );
00464 dvinfo.dwDVAAuxSrc = *( DWORD* ) ( pack.data + 1 );
00465 sample.GetAAUXPack( 0x51, pack );
00466 dvinfo.dwDVAAuxCtl = *( DWORD* ) ( pack.data + 1 );
00467
00468 sample.GetAAUXPack( 0x52, pack );
00469 dvinfo.dwDVAAuxSrc1 = *( DWORD* ) ( pack.data + 1 );
00470 sample.GetAAUXPack( 0x53, pack );
00471 dvinfo.dwDVAAuxCtl1 = *( DWORD* ) ( pack.data + 1 );
00472
00473 sample.GetVAUXPack( 0x60, pack );
00474 dvinfo.dwDVVAuxSrc = *( DWORD* ) ( pack.data + 1 );
00475 sample.GetVAUXPack( 0x61, pack );
00476 dvinfo.dwDVVAuxCtl = *( DWORD* ) ( pack.data + 1 );
00477
00478 #ifdef HAVE_LIBDV
00479 if ( sample.decoder->std == e_dv_std_smpte_314m )
00480 fccHandler = make_fourcc( "dv25" );
00481 #endif
00482 }
|
|
|
Implements FileHandler. Definition at line 531 of file filehandler.cc. References avi, and AVIFile::WriteFrame(). 00532 {
00533 assert( avi != NULL );
00534 try
00535 {
00536 return avi->WriteFrame( frame ) ? 0 : -1;
00537 }
00538 catch (...)
00539 {
00540 return -1;
00541 }
00542 }
|
|
|
Definition at line 173 of file filehandler.h. Referenced by Close(), GetFrame(), SeekAudioFrame(), and ~AVIHandler(). |
|
|
Definition at line 177 of file filehandler.h. Referenced by SeekAudioFrame(). |
|
|
Definition at line 174 of file filehandler.h. Referenced by AVIHandler(), Close(), GetFrame(), and ~AVIHandler(). |
|
|
Definition at line 166 of file filehandler.h. Referenced by Create(), GetFrame(), SeekAudioFrame(), and SetSampleFrame(). |
|
|
Definition at line 176 of file filehandler.h. Referenced by SeekAudioFrame(). |
|
|
Definition at line 164 of file filehandler.h. Referenced by Close(), Create(), FileIsOpen(), GetFileSize(), GetFrame(), GetTotalFrames(), Open(), SeekAudioFrame(), Write(), and ~AVIHandler(). |
|
|
Definition at line 165 of file filehandler.h. Referenced by Create(), GetFormat(), GetFrame(), and Open(). |
|
|
Definition at line 171 of file filehandler.h. Referenced by GetFrame(). |
|
|
Definition at line 169 of file filehandler.h. Referenced by Create(), and SetSampleFrame(). |
|
|
Definition at line 170 of file filehandler.h. Referenced by Create(), and SetSampleFrame(). |
|
|
Definition at line 172 of file filehandler.h. Referenced by Close(), and GetFrame(). |
|
|
Definition at line 175 of file filehandler.h. Referenced by GetFrame(), and Open(). |
|
|
Definition at line 168 of file filehandler.h. Referenced by GetOpenDML(), Open(), and SetOpenDML(). |
|
|
Definition at line 167 of file filehandler.h. Referenced by Create(), and SetSampleFrame(). |
1.4.2