// TODO: this is just a test at the moment... needs to be fixed up and work with memory checking... // void ofQuicktimeSoundPlayer::tryMultiPlay(){ //soundToPlay; //TODO: error checking here! TimeValue srcMovDuration; OSErr err = noErr; Handle audioFileDataRef; OSType audioFileDataRefType; short i, resID = 0; Movie tempMovie; // initialize our movie tempMovie = nil; // create a temporary movie -- we'll add // references to the audio file to this movie tempMovie = NewMovie(newMovieActive); assert(tempMovie != nil); srcMovDuration = GetMovieDuration(soundToPlay); // add multiple references to our audio file // Note: // by not calling BeginMediaEdits/EndMediaEdits // we are telling QuickTime to *not* copy the // actual data - this will give us only references // to the data which are small // add a reference to the source audio file to // our temporary movie err = InsertMovieSegment ( soundToPlay, // our audio file tempMovie, // temporary movie 0, srcMovDuration, GetMovieDuration(tempMovie) ); //printf("here \n"); // for completeness we'll copy the movie settings // from the source file err = CopyMovieSettings(soundToPlay, tempMovie); GoToBeginningOfMovie(tempMovie); StartMovie(tempMovie); soundsForMultiPlay.push_back(tempMovie); //TODO: copy speed, volume, pan settings to this movie? }
TLevelWriter3gp::TLevelWriter3gp(const TFilePath &path, TPropertyGroup *winfo) : TLevelWriter(path, winfo), m_initDone(false), m_IOError(QTNoError), m_pixmap(0), m_compressedData(0), m_gworld(0), m_videoMedia(0), m_videoTrack(0), m_movie(0), m_cancelled(false), m_soundDataRef(0), m_hSoundMovieData(0) { m_frameRate = 12.; QDErr err; //FSSpec fspec; if (QuickTimeStuff::instance()->getStatus() != noErr) { m_IOError = QTNotInstalled; throw TImageException(m_path, buildQTErrorString(m_IOError)); } m_movie = NewMovie(0); if ((err = GetMoviesError() != noErr)) throw TImageException(getFilePath(), "can't create movie"); }
OSErr makeMovieFromVideoFramesFile(char *inDestMovieFile) { Handle dataRef = NULL; OSType dataRefType; ImageDescriptionHandle videoDescH = NULL; OSErr err; #if TARGET_OS_WIN32 err = InitializeQTML(0); if ((err = GetMoviesError()) != noErr) goto bail; #endif err = EnterMovies(); if ((err = GetMoviesError()) != noErr) goto bail; // create a data reference from the full path to the video frames file makeDataRefFromFullPath(inDestMovieFile, &dataRef, &dataRefType); if (dataRef == NULL) goto bail; Movie m = NewMovie(0); if ((err = GetMoviesError()) != noErr) goto bail; // create the video track for the movie Track videoT = NewMovieTrack( m, Long2Fix(kFrameWidth), Long2Fix(kFrameHeight), kNoVolume); if ((err = GetMoviesError()) != noErr) goto bail; // create the video track media Media videoM = NewTrackMedia( videoT, VideoMediaType, kMediaTimeScale, dataRef, dataRefType); if ((err = GetMoviesError()) != noErr) goto bail; videoDescH = (ImageDescriptionHandle)NewHandleClear(sizeof(ImageDescription)); if (videoDescH == NULL) goto bail; // create the ImageDescription that will describe our video track media samples videoDescH[0]->idSize = sizeof(ImageDescription); videoDescH[0]->cType = kCodecType; // the codec type for your data videoDescH[0]->temporalQuality = codecNormalQuality; videoDescH[0]->spatialQuality = codecNormalQuality; videoDescH[0]->width = kFrameWidth; videoDescH[0]->height = kFrameHeight; videoDescH[0]->hRes = 72L << 16; videoDescH[0]->vRes = 72L << 16; videoDescH[0]->depth = 32; videoDescH[0]->clutID = -1; SampleReference64Record videoRef; videoRef.dataOffset.hi = 0; videoRef.dataOffset.lo = 0; videoRef.dataSize = (kFrameWidth*kFrameHeight*4) * kNumberOfSamples; videoRef.durationPerSample = kDurationPerSample; videoRef.numberOfSamples = kNumberOfSamples; videoRef.sampleFlags = 0; // now add all of our media samples to the movie data file. err = AddMediaSampleReferences64(videoM, (SampleDescriptionHandle)videoDescH, 1, &videoRef, 0); if (err != noErr) goto bail; TimeValue mediaDuration = kNumberOfSamples * kDurationPerSample; // inserts a reference to our media samples into the track. err = InsertMediaIntoTrack(videoT, 0, 0, mediaDuration, fixed1); // media's rate (1.0 = media's natural playback rate). if (err != noErr) goto bail; DataHandler outDataHandler; // opens a data handler for our movie storage (the video frames file) err = OpenMovieStorage (dataRef, dataRefType, kDataHCanWrite, &outDataHandler ); if (err != noErr) goto bail; // add a movie to our movie storage container err = AddMovieToStorage (m, outDataHandler ); if (err != noErr) goto bail; err = CloseMovieStorage (outDataHandler); outDataHandler = NULL; bail: if (videoDescH) { DisposeHandle((Handle)videoDescH); } return err; }
bool wxSound::DoPlay(unsigned flags) const { Stop(); Movie movie; switch(m_type) { case wxSound_MEMORY: { if (!wxInitQT()) return false; Handle myHandle, dataRef = nil; MovieImportComponent miComponent; Track targetTrack = nil; TimeValue addedDuration = 0; long outFlags = 0; OSErr err; ComponentResult result; myHandle = NewHandleClear((Size)m_waveLength); BlockMove(m_hSnd, *myHandle, m_waveLength); err = PtrToHand(&myHandle, &dataRef, sizeof(Handle)); if (memcmp(&m_hSnd[8], "WAVE", 4) == 0) miComponent = OpenDefaultComponent(MovieImportType, kQTFileTypeWave); else if (memcmp(&m_hSnd[8], "AIFF", 4) == 0) miComponent = OpenDefaultComponent(MovieImportType, kQTFileTypeAIFF); else if (memcmp(&m_hSnd[8], "AIFC", 4) == 0) miComponent = OpenDefaultComponent(MovieImportType, kQTFileTypeAIFC); else { wxLogSysError(wxT("wxSound - Location in memory does not contain valid data")); return false; } movie = NewMovie(0); result = MovieImportDataRef(miComponent, dataRef, HandleDataHandlerSubType, movie, nil, &targetTrack, nil, &addedDuration, movieImportCreateTrack, &outFlags); if (result != noErr) { wxLogSysError(wxString::Format(wxT("Couldn't import movie data\nError:%i"), (int)result)); } SetMovieVolume(movie, kFullVolume); GoToBeginningOfMovie(movie); DisposeHandle(myHandle); } break; case wxSound_RESOURCE: { SoundComponentData data; unsigned long numframes, offset; ParseSndHeader((SndListHandle)m_hSnd, &data, &numframes, &offset); //m_waveLength = numFrames * data.numChannels; SndChannelPtr pSndChannel; SndNewChannel(&pSndChannel, sampledSynth, initNoInterp + (data.numChannels == 1 ? initMono : initStereo), NULL); if(SndPlay(pSndChannel, (SndListHandle) m_hSnd, flags & wxSOUND_ASYNC ? 1 : 0) != noErr) return false; if (flags & wxSOUND_ASYNC) { lastSoundTimer = ((wxSMTimer*&)m_pTimer) = new wxSMTimer(pSndChannel, m_hSnd, flags & wxSOUND_LOOP ? 1 : 0, &lastSoundIsPlaying); lastSoundIsPlaying = true; ((wxTimer*)m_pTimer)->Start(MOVIE_DELAY, wxTIMER_CONTINUOUS); } else SndDisposeChannel(pSndChannel, TRUE); return true; } break; case wxSound_FILE: { if (!wxInitQT()) return false; OSErr err = noErr ; Handle dataRef = NULL; OSType dataRefType; err = QTNewDataReferenceFromFullPathCFString(wxMacCFStringHolder(m_sndname,wxLocale::GetSystemEncoding()), (UInt32)kQTNativeDefaultPathStyle, 0, &dataRef, &dataRefType); wxASSERT(err == noErr); if (NULL != dataRef || err != noErr) { err = NewMovieFromDataRef( &movie, newMovieDontAskUnresolvedDataRefs , NULL, dataRef, dataRefType ); wxASSERT(err == noErr); DisposeHandle(dataRef); } if (err != noErr) { wxLogSysError( wxString::Format(wxT("wxSound - Could not open file: %s\nError:%i"), m_sndname.c_str(), err ) ); return false; } } break; default: return false; }//end switch(m_type) //Start the movie! StartMovie(movie); if (flags & wxSOUND_ASYNC) { //Start timer and play movie asyncronously lastSoundTimer = ((wxQTTimer*&)m_pTimer) = new wxQTTimer(movie, flags & wxSOUND_LOOP ? 1 : 0, &lastSoundIsPlaying); lastSoundIsPlaying = true; ((wxQTTimer*)m_pTimer)->Start(MOVIE_DELAY, wxTIMER_CONTINUOUS); } else { wxASSERT_MSG(!(flags & wxSOUND_LOOP), wxT("Can't loop and play syncronously at the same time")); //Play movie until it ends, then exit //Note that due to quicktime caching this may not always //work 100% correctly while (!IsMovieDone(movie)) MoviesTask(movie, 1); DisposeMovie(movie); } return true; }
bool wxOSXQuickTimeSoundData::Play(unsigned flags) { if ( m_movie ) Stop(); m_flags = flags; if (!wxInitQT()) return false; if( m_soundHandle ) { Handle dataRef = nil; MovieImportComponent miComponent; Track targetTrack = nil; TimeValue addedDuration = 0; long outFlags = 0; OSErr err; ComponentResult result; err = PtrToHand(&m_soundHandle, &dataRef, sizeof(Handle)); HLock(m_soundHandle); if (memcmp(&(*m_soundHandle)[8], "WAVE", 4) == 0) miComponent = OpenDefaultComponent(MovieImportType, kQTFileTypeWave); else if (memcmp(&(*m_soundHandle)[8], "AIFF", 4) == 0) miComponent = OpenDefaultComponent(MovieImportType, kQTFileTypeAIFF); else if (memcmp(&(*m_soundHandle)[8], "AIFC", 4) == 0) miComponent = OpenDefaultComponent(MovieImportType, kQTFileTypeAIFC); else { HUnlock(m_soundHandle); wxLogSysError(wxT("wxSound - Location in memory does not contain valid data")); return false; } HUnlock(m_soundHandle); m_movie = NewMovie(0); result = MovieImportDataRef(miComponent, dataRef, HandleDataHandlerSubType, m_movie, nil, &targetTrack, nil, &addedDuration, movieImportCreateTrack, &outFlags); if (result != noErr) { wxLogSysError(wxString::Format(wxT("Couldn't import movie data\nError:%i"), (int)result)); } SetMovieVolume(m_movie, kFullVolume); GoToBeginningOfMovie(m_movie); } else { OSErr err = noErr ; Handle dataRef = NULL; OSType dataRefType; err = QTNewDataReferenceFromFullPathCFString(wxCFStringRef(m_sndname,wxLocale::GetSystemEncoding()), (UInt32)kQTNativeDefaultPathStyle, 0, &dataRef, &dataRefType); wxASSERT(err == noErr); if (NULL != dataRef || err != noErr) { err = NewMovieFromDataRef( &m_movie, newMovieDontAskUnresolvedDataRefs , NULL, dataRef, dataRefType ); wxASSERT(err == noErr); DisposeHandle(dataRef); } if (err != noErr) { wxLogSysError( wxString::Format(wxT("wxSound - Could not open file: %s\nError:%i"), m_sndname.c_str(), err ) ); return false; } } //Start the m_movie! StartMovie(m_movie); if (flags & wxSOUND_ASYNC) { CreateAndStartTimer(); } else { wxASSERT_MSG(!(flags & wxSOUND_LOOP), wxT("Can't loop and play syncronously at the same time")); //Play movie until it ends, then exit //Note that due to quicktime caching this may not always //work 100% correctly while (!IsMovieDone(m_movie)) MoviesTask(m_movie, 1); DoStop(); } return true; }
OSErr QTDR_CreateMovieInRAM (void) { Movie myMovie = NULL; Track myTrack = NULL; Media myMedia = NULL; short myResRefNum = 0; short myResID = 0; Handle myDataRef = NULL; Handle myHandle = NULL; FSSpec myFSSpec; OSErr myErr = noErr; // create a new handle to hold the media data myHandle = NewHandleClear(0); if (myHandle == NULL) goto bail; // create a data reference to that handle myDataRef = QTDR_MakeHandleDataRef(myHandle); if (myDataRef == NULL) goto bail; myMovie = NewMovie(newMovieActive); if (myMovie == NULL) goto bail; myErr = SetMovieDefaultDataRef(myMovie, myDataRef, HandleDataHandlerSubType); if (myErr != noErr) goto bail; // create the movie track and media myTrack = NewMovieTrack(myMovie, FixRatio(kVideoTrackWidth, 1), FixRatio(kVideoTrackHeight, 1), kNoVolume); myErr = GetMoviesError(); if (myErr != noErr) goto bail; myMedia = NewTrackMedia(myTrack, VideoMediaType, kVideoTimeScale, NULL, 0); myErr = GetMoviesError(); if (myErr != noErr) goto bail; // create the media samples myErr = BeginMediaEdits(myMedia); if (myErr != noErr) goto bail; myErr = QTDR_AddVideoSamplesToMedia(myMedia, kVideoTrackWidth, kVideoTrackHeight); if (myErr != noErr) goto bail; myErr = EndMediaEdits(myMedia); if (myErr != noErr) goto bail; // add the media to the track myErr = InsertMediaIntoTrack(myTrack, 0, 0, GetMediaDuration(myMedia), fixed1); if (myErr != noErr) goto bail; // add the movie atom to the movie file myErr = AddMovieResource(myMovie, myResRefNum, &myResID, NULL); myFSSpec.name[0] = (unsigned char)0; myFSSpec.parID = 0; myFSSpec.vRefNum = 0; QTFrame_OpenMovieInWindow(myMovie, &myFSSpec); bail: if (myDataRef != NULL) DisposeHandle(myDataRef); return(myErr); }