[haiku-commits] haiku: hrev50806 - in src: kits/media add-ons/media/plugins/ffmpeg

  • From: pulkomandy@xxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Fri, 30 Dec 2016 17:34:42 +0100 (CET)

hrev50806 adds 3 changesets to branch 'master'
old head: 0963770f62c846ec521db95e86ae9c26e3814c70
new head: f621b750f6bf68adcd86805af11d207d2371ed49
overview: 
http://cgit.haiku-os.org/haiku/log/?qt=range&q=f621b750f6bf+%5E0963770f62c8

----------------------------------------------------------------------------

b480a593f2b7: ffmpeg: declare support for AIFF files in the MuxerTable.
  
  There used to be endianness problems, but they have been fixed long ago.
  It is important for some legacy apps, that these are properly recognized
  as B_AIFF_FORMAT_TYPE.

3a530660d0da: ffmpeg: use stream frame count, if provided.
  
  Not sure why that was commented out. Computing the frame count back from
  the frame duration and stream duration can be inaccurate (especially for
  long frame durations and/or short streams). It is important that the
  stream ends exactly when expected. If it ends earlier than the announced
  frame count, an app may be stuck forever waiting for the end, or would
  interpret it as a read error. If it is too long, a buffer overflow may
  occur.

f621b750f6bf: BSoundFile: implement most of it.
  
  Based on the amazing work of puckipedia, this gets BePac Deluxe to play
  fine on Haiku (complete with sound effects and music).
  
  This is based on his original patch, but the irrelevent parts (working
  around bugs in ffmpeg that were fixed since then) are removed.
  
  Fixes #9939.

                             [ Adrien Destugues <pulkomandy@xxxxxxxxxxxxx> ]

----------------------------------------------------------------------------

3 files changed, 54 insertions(+), 14 deletions(-)
.../media/plugins/ffmpeg/AVFormatReader.cpp      |  8 ++--
src/add-ons/media/plugins/ffmpeg/MuxerTable.cpp  | 13 ++++++
src/kits/media/SoundFile.cpp                     | 47 +++++++++++++++-----

############################################################################

Commit:      b480a593f2b73b6f5eb91e51142f95bd2b669e2f
URL:         http://cgit.haiku-os.org/haiku/commit/?id=b480a593f2b7
Author:      Adrien Destugues <pulkomandy@xxxxxxxxxxxxx>
Date:        Fri Dec 30 16:29:44 2016 UTC

ffmpeg: declare support for AIFF files in the MuxerTable.

There used to be endianness problems, but they have been fixed long ago.
It is important for some legacy apps, that these are properly recognized
as B_AIFF_FORMAT_TYPE.

----------------------------------------------------------------------------

diff --git a/src/add-ons/media/plugins/ffmpeg/MuxerTable.cpp 
b/src/add-ons/media/plugins/ffmpeg/MuxerTable.cpp
index da5a487..5c80462 100644
--- a/src/add-ons/media/plugins/ffmpeg/MuxerTable.cpp
+++ b/src/add-ons/media/plugins/ffmpeg/MuxerTable.cpp
@@ -38,6 +38,19 @@ const media_file_format gMuxerTable[] = {
        },
        {
                media_file_format::B_READABLE
+                       | media_file_format::B_KNOWS_RAW_AUDIO,
+               { 0 },
+               B_AIFF_FORMAT_FAMILY,
+               100,
+               { 0 },
+               "audio/x-aiff",
+               "Audio IFF",
+               "aiff",
+               "aiff",
+               { 0 }
+       },
+       {
+               media_file_format::B_READABLE
                        | media_file_format::B_KNOWS_RAW_VIDEO
                        | media_file_format::B_KNOWS_RAW_AUDIO
                        | media_file_format::B_KNOWS_ENCODED_VIDEO

############################################################################

Commit:      3a530660d0da40e212fce8066c591bfaade364a7
URL:         http://cgit.haiku-os.org/haiku/commit/?id=3a530660d0da
Author:      Adrien Destugues <pulkomandy@xxxxxxxxxxxxx>
Date:        Fri Dec 30 16:30:41 2016 UTC

ffmpeg: use stream frame count, if provided.

Not sure why that was commented out. Computing the frame count back from
the frame duration and stream duration can be inaccurate (especially for
long frame durations and/or short streams). It is important that the
stream ends exactly when expected. If it ends earlier than the announced
frame count, an app may be stuck forever waiting for the end, or would
interpret it as a read error. If it is too long, a buffer overflow may
occur.

----------------------------------------------------------------------------

diff --git a/src/add-ons/media/plugins/ffmpeg/AVFormatReader.cpp 
b/src/add-ons/media/plugins/ffmpeg/AVFormatReader.cpp
index b28ead0..796770d 100644
--- a/src/add-ons/media/plugins/ffmpeg/AVFormatReader.cpp
+++ b/src/add-ons/media/plugins/ffmpeg/AVFormatReader.cpp
@@ -29,7 +29,7 @@ extern "C" {
 #include "Utilities.h"
 
 
-//#define TRACE_AVFORMAT_READER
+#define TRACE_AVFORMAT_READER
 #ifdef TRACE_AVFORMAT_READER
 #      define TRACE printf
 #      define TRACE_IO(a...)
@@ -1255,13 +1255,13 @@ AVFormatReader::Stream::GetStreamInfo(int64* frameCount,
        #endif
 
        *frameCount = fStream->nb_frames;
-//     if (*frameCount == 0) {
+       if (*frameCount == 0) {
                // Calculate from duration and frame rate
                *frameCount = (int64)(*duration * frameRate / 1000000LL);
                TRACE("  frameCount calculated: %lld, from context: %lld\n",
                        *frameCount, fStream->nb_frames);
-//     } else
-//             TRACE("  frameCount: %lld\n", *frameCount);
+       } else
+               TRACE("  frameCount: %lld\n", *frameCount);
 
        *format = fFormat;
 

############################################################################

Revision:    hrev50806
Commit:      f621b750f6bf68adcd86805af11d207d2371ed49
URL:         http://cgit.haiku-os.org/haiku/commit/?id=f621b750f6bf
Author:      Adrien Destugues <pulkomandy@xxxxxxxxxxxxx>
Date:        Fri Dec 30 16:32:48 2016 UTC

Ticket:      https://dev.haiku-os.org/ticket/9939

BSoundFile: implement most of it.

Based on the amazing work of puckipedia, this gets BePac Deluxe to play
fine on Haiku (complete with sound effects and music).

This is based on his original patch, but the irrelevent parts (working
around bugs in ffmpeg that were fixed since then) are removed.

Fixes #9939.

----------------------------------------------------------------------------

diff --git a/src/kits/media/SoundFile.cpp b/src/kits/media/SoundFile.cpp
index 7428680..c81a82e 100644
--- a/src/kits/media/SoundFile.cpp
+++ b/src/kits/media/SoundFile.cpp
@@ -239,9 +239,21 @@ size_t
 BSoundFile::ReadFrames(char *buf,
                                           size_t count)
 {
-       UNIMPLEMENTED();
-
-       return 0;
+       size_t frameRead = 0;
+       int64 frames = count;
+       while (count > 0) {
+               status_t status = fMediaTrack->ReadFrames(
+                               reinterpret_cast<void *>(buf), &frames);
+               count -= frames;
+               frameRead += frames;
+               buf += fSampleSize * fChannelCount * frames;
+               if (status != B_OK) {
+                       if (frameRead > 0)
+                               break;
+                       return status;
+               }
+       }
+       return frameRead;
 }
 
 
@@ -249,18 +261,21 @@ size_t
 BSoundFile::WriteFrames(char *buf,
                                                size_t count)
 {
-       UNIMPLEMENTED();
-
-       return 0;
+       return fMediaTrack->WriteFrames(
+                       reinterpret_cast<void *>(buf), count);
 }
 
 
 /* virtual */ off_t
 BSoundFile::SeekToFrame(off_t n)
 {
-       UNIMPLEMENTED();
+       int64 frames = n;
+       status_t status = fMediaTrack->SeekToFrame(&frames);
 
-       return 0;
+       if (status != B_OK)
+               return status;
+
+       return frames;
 }
 
 
@@ -306,6 +321,17 @@ BSoundFile::_init_raw_stats()
 }
 
 
+static int32
+_ParseMimeType(char *mime_type)
+{
+       if (strcmp(mime_type, "audio/x-aiff") == 0)
+               return B_AIFF_FILE;
+       if (strcmp(mime_type, "audio/x-wav") == 0)
+               return B_WAVE_FILE;
+       return B_UNKNOWN_FILE;
+}
+
+
 status_t
 BSoundFile::_ref_to_file(const entry_ref *ref)
 {
@@ -328,14 +354,14 @@ BSoundFile::_ref_to_file(const entry_ref *ref)
        switch (mfi.family) {
                case B_AIFF_FORMAT_FAMILY: fFileFormat = B_AIFF_FILE; break;
                case B_WAV_FORMAT_FAMILY:  fFileFormat = B_WAVE_FILE; break;
-               default:                fFileFormat = B_UNKNOWN_FILE; break;
+               default: fFileFormat = _ParseMimeType(mfi.mime_type); break;
        }
        int trackNum = 0;
        BMediaTrack * track = 0;
        media_format mf;
        while (trackNum < media->CountTracks()) {
                track = media->TrackAt(trackNum);
-               status = track->EncodedFormat(&mf);
+               status = track->DecodedFormat(&mf);
                if (status != B_OK) {
                        media->ReleaseTrack(track);
                        delete media;
@@ -393,6 +419,7 @@ BSoundFile::_ref_to_file(const entry_ref *ref)
        }
        fMediaFile = media;
        fMediaTrack = track;
+       fSoundFile = file;
        return B_OK;
 }
 


Other related posts: