* Coding style clean-up.

* Use std::nothrow and check allocations.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30986 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2009-06-07 19:35:14 +00:00
parent c0e1e0eaac
commit b5ec3e5669
2 changed files with 226 additions and 232 deletions
+124 -115
View File
@@ -1,12 +1,15 @@
/*
* Copyright (c) 2002 - 2009, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _MEDIA_FILE_H #ifndef _MEDIA_FILE_H
#define _MEDIA_FILE_H #define _MEDIA_FILE_H
#include <kernel/image.h> #include <kernel/image.h>
#include <SupportDefs.h>
#include <StorageDefs.h>
#include <List.h> #include <List.h>
#include <MediaDefs.h> #include <MediaDefs.h>
#include <MediaFormats.h> #include <MediaFormats.h>
#include <StorageDefs.h>
namespace BPrivate { namespace BPrivate {
@@ -45,172 +48,178 @@ enum {
// //
class BMediaFile { class BMediaFile {
public: public:
// these four constructors are used for read-only access // these four constructors are used for read-only access
BMediaFile( const entry_ref *ref); BMediaFile(const entry_ref* ref);
BMediaFile( BDataIO * source); // BFile is a BDataIO BMediaFile(BDataIO* source);
BMediaFile( const entry_ref * ref, // BFile is a BDataIO
int32 flags); BMediaFile(const entry_ref* ref, int32 flags);
BMediaFile( BDataIO * source, BMediaFile(BDataIO* source, int32 flags);
int32 flags); // BFile is a BDataIO
// these three constructors are for read-write access // these three constructors are for read-write access
BMediaFile(const entry_ref *ref, // these two are write-only BMediaFile(const entry_ref* ref,
const media_file_format * mfi, const media_file_format* mfi,
int32 flags=0); int32 flags = 0);
BMediaFile(BDataIO *destination, // BFile is a BDataIO BMediaFile(BDataIO* destination,
const media_file_format * mfi, const media_file_format* mfi,
int32 flags=0); int32 flags = 0);
BMediaFile(const media_file_format * mfi, // set file later using SetTo() BMediaFile(const media_file_format* mfi,
int32 flags=0); int32 flags = 0);
// set file later using SetTo()
status_t SetTo(const entry_ref *ref); virtual ~BMediaFile();
status_t SetTo(BDataIO *destination); // BFile is a BDataIO
status_t SetTo(const entry_ref* ref);
status_t SetTo(BDataIO* destination);
virtual ~BMediaFile(); status_t InitCheck() const;
status_t InitCheck() const;
// Get info about the underlying file format. // Get info about the underlying file format.
status_t GetFileFormatInfo(media_file_format *mfi) const; status_t GetFileFormatInfo(media_file_format* mfi) const;
// //
// These functions are for read-only access to a media file. // These functions are for read-only access to a media file.
// The data is read using the BMediaTrack object. // The data is read using the BMediaTrack object.
// //
const char *Copyright(void) const; const char* Copyright() const;
int32 CountTracks() const; int32 CountTracks() const;
// Can be called multiple times with the same index. You must call // Can be called multiple times with the same index. You must call
// ReleaseTrack() when you're done with a track. // ReleaseTrack() when you're done with a track.
BMediaTrack *TrackAt(int32 index); BMediaTrack* TrackAt(int32 index);
// Release the resource used by a given BMediaTrack object, to reduce // Release the resource used by a given BMediaTrack object, to reduce
// the memory usage of your application. The specific 'track' object // the memory usage of your application. The specific 'track' object
// can no longer be used, but you can create another one by calling // can no longer be used, but you can create another one by calling
// TrackAt() with the same track index. // TrackAt() with the same track index.
status_t ReleaseTrack(BMediaTrack *track); status_t ReleaseTrack(BMediaTrack* track);
// A convenience. // A convenience. Deleting a BMediaFile will also call this.
status_t ReleaseAllTracks(void); status_t ReleaseAllTracks();
// Create and add a track to the media file // Create and add a track to the media file
BMediaTrack *CreateTrack(media_format *mf, const media_codec_info *mci, uint32 flags=0); BMediaTrack* CreateTrack(media_format* mf,
const media_codec_info* mci,
uint32 flags = 0);
// Create and add a raw track to the media file (it has no encoder) // Create and add a raw track to the media file (it has no encoder)
BMediaTrack *CreateTrack(media_format *mf, uint32 flags=0); BMediaTrack* CreateTrack(media_format* mf,
uint32 flags = 0);
// Lets you set the copyright info for the entire file // Lets you set the copyright info for the entire file
status_t AddCopyright(const char *data); status_t AddCopyright(const char* data);
// Call this to add user-defined chunks to a file (if they're supported) // Call this to add user-defined chunks to a file (if they're supported)
status_t AddChunk(int32 type, const void *data, size_t size); status_t AddChunk(int32 type, const void* data,
size_t size);
// After you have added all the tracks you want, call this // After you have added all the tracks you want, call this
status_t CommitHeader(void); status_t CommitHeader();
// After you have written all the data to the track objects, call this // After you have written all the data to the track objects, call this
status_t CloseFile(void); status_t CloseFile();
// This is for controlling file format parameters // This is for controlling file format parameters
// returns a copy of the parameter web // returns a copy of the parameter web
status_t GetParameterWeb(BParameterWeb** outWeb); status_t GetParameterWeb(BParameterWeb** outWeb);
status_t GetParameterValue(int32 id, void *valu, size_t *size); status_t GetParameterValue(int32 id, void* value,
status_t SetParameterValue(int32 id, const void *valu, size_t size); size_t* size);
BView *GetParameterView(); status_t SetParameterValue(int32 id, const void* value,
size_t size);
BView* GetParameterView();
// For the future... // For the future...
virtual status_t Perform(int32 selector, void * data); virtual status_t Perform(int32 selector, void* data);
private: private:
// deprecated, but for R5 compatibility // deprecated, but for R5 compatibility
BParameterWeb *Web(); BParameterWeb* Web();
// Does nothing, returns B_ERROR, for Zeta compatiblity only // Does nothing, returns B_ERROR, for Zeta compatiblity only
status_t ControlFile(int32 selector, void * io_data, size_t size); status_t ControlFile(int32 selector, void* ioData,
size_t size);
BPrivate::media::MediaExtractor *fExtractor; BPrivate::media::MediaExtractor* fExtractor;
int32 _reserved_BMediaFile_was_fExtractorID; int32 _reserved_BMediaFile_was_fExtractorID;
int32 fTrackNum; int32 fTrackNum;
status_t fErr; status_t fErr;
BPrivate::_AddonManager *fEncoderMgr; BPrivate::_AddonManager* fEncoderMgr;
BPrivate::_AddonManager *fWriterMgr; BPrivate::_AddonManager* fWriterMgr;
BPrivate::MediaWriter *fWriter; BPrivate::MediaWriter* fWriter;
int32 fWriterID; int32 fWriterID;
media_file_format fMFI; media_file_format fMFI;
bool fFileClosed; bool fFileClosed;
bool fDeleteSource; bool fDeleteSource;
bool _reserved_was_fUnused[2]; bool _reserved_was_fUnused[2];
BMediaTrack **fTrackList; BMediaTrack** fTrackList;
void Init(); void _Init();
void InitReader(BDataIO *source, int32 flags = 0); void _InitReader(BDataIO* source, int32 flags = 0);
void InitWriter(BDataIO *source, const media_file_format * mfi, void _InitWriter(BDataIO* source,
int32 flags); const media_file_format* mfi, int32 flags);
BMediaFile(); BMediaFile();
BMediaFile(const BMediaFile&); BMediaFile(const BMediaFile&);
BMediaFile& operator=(const BMediaFile&); BMediaFile& operator=(const BMediaFile&);
BDataIO *fSource; BDataIO* fSource;
/* fbc data and virtuals */ // FBC data and virtuals
uint32 _reserved_BMediaFile_[32]; uint32 _reserved_BMediaFile_[32];
virtual status_t _Reserved_BMediaFile_0(int32 arg, ...); virtual status_t _Reserved_BMediaFile_0(int32 arg, ...);
virtual status_t _Reserved_BMediaFile_1(int32 arg, ...); virtual status_t _Reserved_BMediaFile_1(int32 arg, ...);
virtual status_t _Reserved_BMediaFile_2(int32 arg, ...); virtual status_t _Reserved_BMediaFile_2(int32 arg, ...);
virtual status_t _Reserved_BMediaFile_3(int32 arg, ...); virtual status_t _Reserved_BMediaFile_3(int32 arg, ...);
virtual status_t _Reserved_BMediaFile_4(int32 arg, ...); virtual status_t _Reserved_BMediaFile_4(int32 arg, ...);
virtual status_t _Reserved_BMediaFile_5(int32 arg, ...); virtual status_t _Reserved_BMediaFile_5(int32 arg, ...);
virtual status_t _Reserved_BMediaFile_6(int32 arg, ...); virtual status_t _Reserved_BMediaFile_6(int32 arg, ...);
virtual status_t _Reserved_BMediaFile_7(int32 arg, ...); virtual status_t _Reserved_BMediaFile_7(int32 arg, ...);
virtual status_t _Reserved_BMediaFile_8(int32 arg, ...); virtual status_t _Reserved_BMediaFile_8(int32 arg, ...);
virtual status_t _Reserved_BMediaFile_9(int32 arg, ...); virtual status_t _Reserved_BMediaFile_9(int32 arg, ...);
virtual status_t _Reserved_BMediaFile_10(int32 arg, ...); virtual status_t _Reserved_BMediaFile_10(int32 arg, ...);
virtual status_t _Reserved_BMediaFile_11(int32 arg, ...); virtual status_t _Reserved_BMediaFile_11(int32 arg, ...);
virtual status_t _Reserved_BMediaFile_12(int32 arg, ...); virtual status_t _Reserved_BMediaFile_12(int32 arg, ...);
virtual status_t _Reserved_BMediaFile_13(int32 arg, ...); virtual status_t _Reserved_BMediaFile_13(int32 arg, ...);
virtual status_t _Reserved_BMediaFile_14(int32 arg, ...); virtual status_t _Reserved_BMediaFile_14(int32 arg, ...);
virtual status_t _Reserved_BMediaFile_15(int32 arg, ...); virtual status_t _Reserved_BMediaFile_15(int32 arg, ...);
virtual status_t _Reserved_BMediaFile_16(int32 arg, ...); virtual status_t _Reserved_BMediaFile_16(int32 arg, ...);
virtual status_t _Reserved_BMediaFile_17(int32 arg, ...); virtual status_t _Reserved_BMediaFile_17(int32 arg, ...);
virtual status_t _Reserved_BMediaFile_18(int32 arg, ...); virtual status_t _Reserved_BMediaFile_18(int32 arg, ...);
virtual status_t _Reserved_BMediaFile_19(int32 arg, ...); virtual status_t _Reserved_BMediaFile_19(int32 arg, ...);
virtual status_t _Reserved_BMediaFile_20(int32 arg, ...); virtual status_t _Reserved_BMediaFile_20(int32 arg, ...);
virtual status_t _Reserved_BMediaFile_21(int32 arg, ...); virtual status_t _Reserved_BMediaFile_21(int32 arg, ...);
virtual status_t _Reserved_BMediaFile_22(int32 arg, ...); virtual status_t _Reserved_BMediaFile_22(int32 arg, ...);
virtual status_t _Reserved_BMediaFile_23(int32 arg, ...); virtual status_t _Reserved_BMediaFile_23(int32 arg, ...);
virtual status_t _Reserved_BMediaFile_24(int32 arg, ...); virtual status_t _Reserved_BMediaFile_24(int32 arg, ...);
virtual status_t _Reserved_BMediaFile_25(int32 arg, ...); virtual status_t _Reserved_BMediaFile_25(int32 arg, ...);
virtual status_t _Reserved_BMediaFile_26(int32 arg, ...); virtual status_t _Reserved_BMediaFile_26(int32 arg, ...);
virtual status_t _Reserved_BMediaFile_27(int32 arg, ...); virtual status_t _Reserved_BMediaFile_27(int32 arg, ...);
virtual status_t _Reserved_BMediaFile_28(int32 arg, ...); virtual status_t _Reserved_BMediaFile_28(int32 arg, ...);
virtual status_t _Reserved_BMediaFile_29(int32 arg, ...); virtual status_t _Reserved_BMediaFile_29(int32 arg, ...);
virtual status_t _Reserved_BMediaFile_30(int32 arg, ...); virtual status_t _Reserved_BMediaFile_30(int32 arg, ...);
virtual status_t _Reserved_BMediaFile_31(int32 arg, ...); virtual status_t _Reserved_BMediaFile_31(int32 arg, ...);
virtual status_t _Reserved_BMediaFile_32(int32 arg, ...); virtual status_t _Reserved_BMediaFile_32(int32 arg, ...);
virtual status_t _Reserved_BMediaFile_33(int32 arg, ...); virtual status_t _Reserved_BMediaFile_33(int32 arg, ...);
virtual status_t _Reserved_BMediaFile_34(int32 arg, ...); virtual status_t _Reserved_BMediaFile_34(int32 arg, ...);
virtual status_t _Reserved_BMediaFile_35(int32 arg, ...); virtual status_t _Reserved_BMediaFile_35(int32 arg, ...);
virtual status_t _Reserved_BMediaFile_36(int32 arg, ...); virtual status_t _Reserved_BMediaFile_36(int32 arg, ...);
virtual status_t _Reserved_BMediaFile_37(int32 arg, ...); virtual status_t _Reserved_BMediaFile_37(int32 arg, ...);
virtual status_t _Reserved_BMediaFile_38(int32 arg, ...); virtual status_t _Reserved_BMediaFile_38(int32 arg, ...);
virtual status_t _Reserved_BMediaFile_39(int32 arg, ...); virtual status_t _Reserved_BMediaFile_39(int32 arg, ...);
virtual status_t _Reserved_BMediaFile_40(int32 arg, ...); virtual status_t _Reserved_BMediaFile_40(int32 arg, ...);
virtual status_t _Reserved_BMediaFile_41(int32 arg, ...); virtual status_t _Reserved_BMediaFile_41(int32 arg, ...);
virtual status_t _Reserved_BMediaFile_42(int32 arg, ...); virtual status_t _Reserved_BMediaFile_42(int32 arg, ...);
virtual status_t _Reserved_BMediaFile_43(int32 arg, ...); virtual status_t _Reserved_BMediaFile_43(int32 arg, ...);
virtual status_t _Reserved_BMediaFile_44(int32 arg, ...); virtual status_t _Reserved_BMediaFile_44(int32 arg, ...);
virtual status_t _Reserved_BMediaFile_45(int32 arg, ...); virtual status_t _Reserved_BMediaFile_45(int32 arg, ...);
virtual status_t _Reserved_BMediaFile_46(int32 arg, ...); virtual status_t _Reserved_BMediaFile_46(int32 arg, ...);
virtual status_t _Reserved_BMediaFile_47(int32 arg, ...); virtual status_t _Reserved_BMediaFile_47(int32 arg, ...);
}; };
#endif #endif
+102 -117
View File
@@ -1,108 +1,82 @@
/* /*
* Copyright (c) 2002-2004, Marcus Overhagen <[email protected]> * Copyright (c) 2002-2004, Marcus Overhagen <[email protected]>
* All rights reserved. * All rights reserved. Distributed under the terms of the MIT License.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include <MediaFile.h> #include <MediaFile.h>
#include <new>
#include <string.h>
#include <MediaTrack.h> #include <MediaTrack.h>
#include <File.h> #include <File.h>
#include <string.h>
#include "MediaExtractor.h" #include "MediaExtractor.h"
#include "debug.h" #include "debug.h"
/************************************************************* BMediaFile::BMediaFile(const entry_ref* ref)
* public BMediaFile
*************************************************************/
BMediaFile::BMediaFile(const entry_ref *ref)
{ {
CALLED(); CALLED();
Init(); _Init();
fDeleteSource = true; fDeleteSource = true;
InitReader(new BFile(ref, O_RDONLY)); _InitReader(new (std::nothrow) BFile(ref, O_RDONLY));
} }
BMediaFile::BMediaFile(BDataIO * source) BMediaFile::BMediaFile(BDataIO* source)
{ {
CALLED(); CALLED();
Init(); _Init();
InitReader(source); _InitReader(source);
} }
BMediaFile::BMediaFile(const entry_ref * ref, BMediaFile::BMediaFile(const entry_ref* ref, int32 flags)
int32 flags)
{ {
CALLED(); CALLED();
Init(); _Init();
fDeleteSource = true; fDeleteSource = true;
InitReader(new BFile(ref, O_RDONLY), flags); _InitReader(new (std::nothrow) BFile(ref, O_RDONLY), flags);
} }
BMediaFile::BMediaFile(BDataIO * source, BMediaFile::BMediaFile(BDataIO* source, int32 flags)
int32 flags)
{ {
CALLED(); CALLED();
Init(); _Init();
InitReader(source, flags); _InitReader(source, flags);
} }
BMediaFile::BMediaFile(const entry_ref *ref, BMediaFile::BMediaFile(const entry_ref* ref, const media_file_format* mfi,
const media_file_format * mfi, int32 flags)
int32 flags)
{ {
CALLED(); CALLED();
Init(); _Init();
fDeleteSource = true; fDeleteSource = true;
InitWriter(new BFile(ref, O_WRONLY), mfi, flags); _InitWriter(new (std::nothrow) BFile(ref, O_WRONLY), mfi, flags);
} }
BMediaFile::BMediaFile(BDataIO *destination, BMediaFile::BMediaFile(BDataIO* destination, const media_file_format* mfi,
const media_file_format * mfi, int32 flags)
int32 flags)
{ {
CALLED(); CALLED();
Init(); _Init();
InitWriter(destination, mfi, flags); _InitWriter(destination, mfi, flags);
} }
// File will be set later by SetTo() // File will be set later by SetTo()
BMediaFile::BMediaFile(const media_file_format * mfi, BMediaFile::BMediaFile(const media_file_format* mfi, int32 flags)
int32 flags)
{ {
debugger("BMediaFile::BMediaFile not implemented"); debugger("BMediaFile::BMediaFile not implemented");
} }
status_t status_t
BMediaFile::SetTo(const entry_ref *ref) BMediaFile::SetTo(const entry_ref* ref)
{ {
debugger("BMediaFile::SetTo not implemented"); debugger("BMediaFile::SetTo not implemented");
return B_OK; return B_OK;
@@ -110,14 +84,13 @@ BMediaFile::SetTo(const entry_ref *ref)
status_t status_t
BMediaFile::SetTo(BDataIO *destination) BMediaFile::SetTo(BDataIO* destination)
{ {
debugger("BMediaFile::SetTo not implemented"); debugger("BMediaFile::SetTo not implemented");
return B_OK; return B_OK;
} }
/* virtual */
BMediaFile::~BMediaFile() BMediaFile::~BMediaFile()
{ {
CALLED(); CALLED();
@@ -140,9 +113,11 @@ BMediaFile::InitCheck() const
// Get info about the underlying file format. // Get info about the underlying file format.
status_t status_t
BMediaFile::GetFileFormatInfo(media_file_format *mfi) const BMediaFile::GetFileFormatInfo(media_file_format* mfi) const
{ {
CALLED(); CALLED();
if (mfi == NULL)
return B_BAD_VALUE;
if (fErr) if (fErr)
return B_ERROR; return B_ERROR;
*mfi = fMFI; *mfi = fMFI;
@@ -150,8 +125,8 @@ BMediaFile::GetFileFormatInfo(media_file_format *mfi) const
} }
const char * const char*
BMediaFile::Copyright(void) const BMediaFile::Copyright() const
{ {
return fExtractor->Copyright(); return fExtractor->Copyright();
} }
@@ -166,15 +141,17 @@ BMediaFile::CountTracks() const
// Can be called multiple times with the same index. You must call // Can be called multiple times with the same index. You must call
// ReleaseTrack() when you're done with a track. // ReleaseTrack() when you're done with a track.
BMediaTrack * BMediaTrack*
BMediaFile::TrackAt(int32 index) BMediaFile::TrackAt(int32 index)
{ {
CALLED(); CALLED();
if (!fTrackList || !fExtractor || index < 0 || index >= fTrackNum) if (fTrackList == NULL || fExtractor == NULL
return 0; || index < 0 || index >= fTrackNum) {
if (!fTrackList[index]) { return NULL;
}
if (fTrackList[index] == NULL) {
TRACE("BMediaFile::TrackAt, creating new track for index %ld\n", index); TRACE("BMediaFile::TrackAt, creating new track for index %ld\n", index);
fTrackList[index] = new BMediaTrack(fExtractor, index); fTrackList[index] = new (std::nothrow) BMediaTrack(fExtractor, index);
TRACE("BMediaFile::TrackAt, new track is %p\n", fTrackList[index]); TRACE("BMediaFile::TrackAt, new track is %p\n", fTrackList[index]);
} }
return fTrackList[index]; return fTrackList[index];
@@ -186,16 +163,17 @@ BMediaFile::TrackAt(int32 index)
// can no longer be used, but you can create another one by calling // can no longer be used, but you can create another one by calling
// TrackAt() with the same track index. // TrackAt() with the same track index.
status_t status_t
BMediaFile::ReleaseTrack(BMediaTrack *track) BMediaFile::ReleaseTrack(BMediaTrack* track)
{ {
CALLED(); CALLED();
if (!fTrackList || !track) if (!fTrackList || !track)
return B_ERROR; return B_ERROR;
for (int32 i = 0; i < fTrackNum; i++) { for (int32 i = 0; i < fTrackNum; i++) {
if (fTrackList[i] == track) { if (fTrackList[i] == track) {
TRACE("BMediaFile::ReleaseTrack, releasing track %p with index %ld\n", track, i); TRACE("BMediaFile::ReleaseTrack, releasing track %p with index "
"%ld\n", track, i);
delete track; delete track;
fTrackList[i] = 0; fTrackList[i] = NULL;
return B_OK; return B_OK;
} }
} }
@@ -205,16 +183,17 @@ BMediaFile::ReleaseTrack(BMediaTrack *track)
status_t status_t
BMediaFile::ReleaseAllTracks(void) BMediaFile::ReleaseAllTracks()
{ {
CALLED(); CALLED();
if (!fTrackList) if (!fTrackList)
return B_ERROR; return B_ERROR;
for (int32 i = 0; i < fTrackNum; i++) { for (int32 i = 0; i < fTrackNum; i++) {
if (fTrackList[i]) { if (fTrackList[i]) {
TRACE("BMediaFile::ReleaseAllTracks, releasing track %p with index %ld\n", fTrackList[i], i); TRACE("BMediaFile::ReleaseAllTracks, releasing track %p with "
"index %ld\n", fTrackList[i], i);
delete fTrackList[i]; delete fTrackList[i];
fTrackList[i] = 0; fTrackList[i] = NULL;
} }
} }
return B_OK; return B_OK;
@@ -222,10 +201,9 @@ BMediaFile::ReleaseAllTracks(void)
// Create and add a track to the media file // Create and add a track to the media file
BMediaTrack * BMediaTrack*
BMediaFile::CreateTrack(media_format *mf, BMediaFile::CreateTrack(media_format* mf, const media_codec_info* mci,
const media_codec_info *mci, uint32 flags)
uint32 flags)
{ {
UNIMPLEMENTED(); UNIMPLEMENTED();
return 0; return 0;
@@ -233,33 +211,30 @@ BMediaFile::CreateTrack(media_format *mf,
// Create and add a raw track to the media file (it has no encoder) // Create and add a raw track to the media file (it has no encoder)
BMediaTrack * BMediaTrack*
BMediaFile::CreateTrack(media_format *mf, uint32 flags) BMediaFile::CreateTrack(media_format* mf, uint32 flags)
{ {
return CreateTrack(mf, NULL, flags); return CreateTrack(mf, NULL, flags);
} }
// For BeOS R5 compatibility // For BeOS R5 compatibility
extern "C" BMediaTrack * CreateTrack__10BMediaFileP12media_formatPC16media_codec_info( extern "C" BMediaTrack*
BMediaFile *self, media_format *mf, const media_codec_info *mci);
BMediaTrack *
CreateTrack__10BMediaFileP12media_formatPC16media_codec_info( CreateTrack__10BMediaFileP12media_formatPC16media_codec_info(
BMediaFile *self, BMediaFile* self, media_format* mf, const media_codec_info* mci);
media_format *mf, BMediaTrack*
const media_codec_info *mci) CreateTrack__10BMediaFileP12media_formatPC16media_codec_info(BMediaFile* self,
media_format* mf, const media_codec_info* mci)
{ {
return self->CreateTrack(mf, mci, 0); return self->CreateTrack(mf, mci, 0);
} }
// For BeOS R5 compatibility // For BeOS R5 compatibility
extern "C" BMediaTrack * CreateTrack__10BMediaFileP12media_format( extern "C" BMediaTrack* CreateTrack__10BMediaFileP12media_format(
BMediaFile *self, media_format *mf); BMediaFile* self, media_format* mf);
BMediaTrack * BMediaTrack*
CreateTrack__10BMediaFileP12media_format( CreateTrack__10BMediaFileP12media_format(BMediaFile* self, media_format* mf)
BMediaFile *self,
media_format *mf)
{ {
return self->CreateTrack(mf, NULL, 0); return self->CreateTrack(mf, NULL, 0);
} }
@@ -267,7 +242,7 @@ CreateTrack__10BMediaFileP12media_format(
// Lets you set the copyright info for the entire file // Lets you set the copyright info for the entire file
status_t status_t
BMediaFile::AddCopyright(const char *data) BMediaFile::AddCopyright(const char* data)
{ {
UNIMPLEMENTED(); UNIMPLEMENTED();
return B_OK; return B_OK;
@@ -276,7 +251,7 @@ BMediaFile::AddCopyright(const char *data)
// Call this to add user-defined chunks to a file (if they're supported) // Call this to add user-defined chunks to a file (if they're supported)
status_t status_t
BMediaFile::AddChunk(int32 type, const void *data, size_t size) BMediaFile::AddChunk(int32 type, const void* data, size_t size)
{ {
UNIMPLEMENTED(); UNIMPLEMENTED();
return B_OK; return B_OK;
@@ -285,7 +260,7 @@ BMediaFile::AddChunk(int32 type, const void *data, size_t size)
// After you have added all the tracks you want, call this // After you have added all the tracks you want, call this
status_t status_t
BMediaFile::CommitHeader(void) BMediaFile::CommitHeader()
{ {
UNIMPLEMENTED(); UNIMPLEMENTED();
return B_OK; return B_OK;
@@ -294,7 +269,7 @@ BMediaFile::CommitHeader(void)
// After you have written all the data to the track objects, call this // After you have written all the data to the track objects, call this
status_t status_t
BMediaFile::CloseFile(void) BMediaFile::CloseFile()
{ {
UNIMPLEMENTED(); UNIMPLEMENTED();
return B_OK; return B_OK;
@@ -312,7 +287,7 @@ BMediaFile::GetParameterWeb(BParameterWeb** outWeb)
// deprecated BeOS R5 API // deprecated BeOS R5 API
BParameterWeb * BParameterWeb*
BMediaFile::Web() BMediaFile::Web()
{ {
UNIMPLEMENTED(); UNIMPLEMENTED();
@@ -321,7 +296,7 @@ BMediaFile::Web()
status_t status_t
BMediaFile::GetParameterValue(int32 id, void *valu, size_t *size) BMediaFile::GetParameterValue(int32 id, void* value, size_t* size)
{ {
UNIMPLEMENTED(); UNIMPLEMENTED();
return B_OK; return B_OK;
@@ -329,14 +304,14 @@ BMediaFile::GetParameterValue(int32 id, void *valu, size_t *size)
status_t status_t
BMediaFile::SetParameterValue(int32 id, const void *valu, size_t size) BMediaFile::SetParameterValue(int32 id, const void* value, size_t size)
{ {
UNIMPLEMENTED(); UNIMPLEMENTED();
return B_OK; return B_OK;
} }
BView * BView*
BMediaFile::GetParameterView() BMediaFile::GetParameterView()
{ {
UNIMPLEMENTED(); UNIMPLEMENTED();
@@ -344,8 +319,8 @@ BMediaFile::GetParameterView()
} }
/* virtual */ status_t status_t
BMediaFile::Perform(int32 selector, void * data) BMediaFile::Perform(int32 selector, void* data)
{ {
UNIMPLEMENTED(); UNIMPLEMENTED();
return B_OK; return B_OK;
@@ -353,59 +328,69 @@ BMediaFile::Perform(int32 selector, void * data)
status_t status_t
BMediaFile::ControlFile(int32 selector, void * io_data, size_t size) BMediaFile::ControlFile(int32 selector, void* ioData, size_t size)
{ {
UNIMPLEMENTED(); UNIMPLEMENTED();
return B_ERROR; return B_ERROR;
} }
/************************************************************* // #pragma mark - private
* private BMediaFile
*************************************************************/
void void
BMediaFile::Init() BMediaFile::_Init()
{ {
CALLED(); CALLED();
fSource = 0;
fSource = NULL;
fTrackNum = 0; fTrackNum = 0;
fTrackList = 0; fTrackList = NULL;
fExtractor = 0; fExtractor = NULL;
fErr = B_OK; fErr = B_OK;
fDeleteSource = false; fDeleteSource = false;
// not used so far: // not used so far:
fEncoderMgr = 0; fEncoderMgr = NULL;
fWriterMgr = 0; fWriterMgr = NULL;
fWriter = 0; fWriter = NULL;
fWriterID = 0; fWriterID = 0;
fFileClosed = 0; fFileClosed = false;
} }
void void
BMediaFile::InitReader(BDataIO *source, int32 flags) BMediaFile::_InitReader(BDataIO* source, int32 flags)
{ {
CALLED(); CALLED();
if (source == NULL)
return;
fSource = source; fSource = source;
fExtractor = new MediaExtractor(source, flags); fExtractor = new (std::nothrow) MediaExtractor(source, flags);
fErr = fExtractor->InitCheck(); if (fExtractor == NULL)
if (fErr) fErr = B_NO_MEMORY;
else
fErr = fExtractor->InitCheck();
if (fErr != B_OK)
return; return;
fExtractor->GetFileFormatInfo(&fMFI); fExtractor->GetFileFormatInfo(&fMFI);
fTrackNum = fExtractor->StreamCount(); fTrackNum = fExtractor->StreamCount();
fTrackList = new BMediaTrack *[fTrackNum]; fTrackList = new (std::nothrow) BMediaTrack*[fTrackNum];
memset(fTrackList, 0, fTrackNum * sizeof(BMediaTrack *)); if (fTrackList == NULL) {
fErr = B_NO_MEMORY;
return;
}
memset(fTrackList, 0, fTrackNum * sizeof(BMediaTrack*));
} }
void void
BMediaFile::InitWriter(BDataIO *source, const media_file_format * mfi, int32 flags) BMediaFile::_InitWriter(BDataIO* source, const media_file_format* mfi,
int32 flags)
{ {
UNIMPLEMENTED(); UNIMPLEMENTED();
fSource = source; fSource = source;