From d48deeab21e4042fc00bc10ab2edf21409198550 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Sun, 19 Sep 2010 12:05:01 +0000 Subject: [PATCH] * Coding style. * Always use keyframes. The BMediaTrack may not be able to implement FindKeyFrameForFrame(), so the detection may not work even though the track really does use keyframes. If it doesn't, then no harm is done anyway. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38721 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../supplier/MediaTrackAudioSupplier.cpp | 73 ++++++++++--------- 1 file changed, 40 insertions(+), 33 deletions(-) diff --git a/src/apps/mediaplayer/supplier/MediaTrackAudioSupplier.cpp b/src/apps/mediaplayer/supplier/MediaTrackAudioSupplier.cpp index a97f78f82a..e9a68f14d0 100644 --- a/src/apps/mediaplayer/supplier/MediaTrackAudioSupplier.cpp +++ b/src/apps/mediaplayer/supplier/MediaTrackAudioSupplier.cpp @@ -239,40 +239,47 @@ MediaTrackAudioSupplier::_InitFromTrack() TRACE("_InitFromTrack()\n"); // Try to suggest a big buffer size, we do a lot of caching... fFormat.u.raw_audio.buffer_size = 16384; - if (fMediaTrack && fMediaTrack->DecodedFormat(&fFormat) == B_OK - && fFormat.type == B_MEDIA_RAW_AUDIO) { - - #ifdef TRACE_AUDIO_SUPPLIER - char formatString[256]; - string_for_format(fFormat, formatString, 256); - TRACE("_InitFromTrack(): format is: %s\n", formatString); - TRACE("_InitFromTrack(): buffer size: %ld\n", - fFormat.u.raw_audio.buffer_size); - #endif - - fBuffer = new (nothrow) char[fFormat.u.raw_audio.buffer_size]; - _AllocateBuffers(); - - // Find out, if the track has key frames: as a heuristic we - // check, if the first and the second frame have the same backward - // key frame. - // Note: It shouldn't harm that much, if we're wrong and the - // track has key frame although we found out that it has not. - int64 keyFrame0 = 0; - int64 keyFrame1 = 1; - fMediaTrack->FindKeyFrameForFrame(&keyFrame0, - B_MEDIA_SEEK_CLOSEST_BACKWARD); - fMediaTrack->FindKeyFrameForFrame(&keyFrame1, - B_MEDIA_SEEK_CLOSEST_BACKWARD); - fHasKeyFrames = (keyFrame0 == keyFrame1); - - // get the length of the track - fCountFrames = fMediaTrack->CountFrames(); - - TRACE("_InitFromTrack(): keyframes: %d, frame count: %lld\n", - fHasKeyFrames, fCountFrames); - } else + if (fMediaTrack == NULL || fMediaTrack->DecodedFormat(&fFormat) != B_OK + || fFormat.type != B_MEDIA_RAW_AUDIO) { fMediaTrack = NULL; + return; + } + + #ifdef TRACE_AUDIO_SUPPLIER + char formatString[256]; + string_for_format(fFormat, formatString, 256); + TRACE("_InitFromTrack(): format is: %s\n", formatString); + TRACE("_InitFromTrack(): buffer size: %ld\n", + fFormat.u.raw_audio.buffer_size); + #endif + + fBuffer = new (nothrow) char[fFormat.u.raw_audio.buffer_size]; + _AllocateBuffers(); + + // Find out, if the track has key frames: as a heuristic we + // check, if the first and the second frame have the same backward + // key frame. + // Note: It shouldn't harm that much, if we're wrong and the + // track has key frame although we found out that it has not. +#if 0 + int64 keyFrame0 = 0; + int64 keyFrame1 = 1; + fMediaTrack->FindKeyFrameForFrame(&keyFrame0, + B_MEDIA_SEEK_CLOSEST_BACKWARD); + fMediaTrack->FindKeyFrameForFrame(&keyFrame1, + B_MEDIA_SEEK_CLOSEST_BACKWARD); + fHasKeyFrames = (keyFrame0 == keyFrame1); +#else + fHasKeyFrames = true; +#endif + + // get the length of the track + fCountFrames = fMediaTrack->CountFrames(); + + TRACE("_InitFromTrack(): keyframes: %d, frame count: %lld\n", + fHasKeyFrames, fCountFrames); + printf("_InitFromTrack(): keyframes: %d, frame count: %lld\n", + fHasKeyFrames, fCountFrames); } // _FramesPerBuffer