* Writer::WriteChunk() takes media_encode_info* instead of flags.
* Improved Encoder API towards what we need for the get_next_encoder() variants and the BMediaTrack API. * Implemented the rest of MediaWriter. Still undecided what to make of AddTrackInfo(). BMediaEncoder has that as well, which hints that this is something the Encoder needs to support. But it could also be that this is only possible to support in Writer. * Wired a lot of previously unimplemented methods in BMediaFile and BMediaTrack needed for write support. If I have not overlooked anything, only the parameter stuff is still unimplemented now. This is all untested, since the FFMpeg Encoder and Writer are still only stubs. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32013 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
/*
|
||||
* Copyright 2002-2009, Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
* Distributed under the terms of the MIT license.
|
||||
*/
|
||||
#ifndef _MEDIA_FILE_H
|
||||
#define _MEDIA_FILE_H
|
||||
|
||||
|
||||
#include <image.h>
|
||||
#include <List.h>
|
||||
#include <MediaDefs.h>
|
||||
@@ -15,8 +16,8 @@
|
||||
namespace BPrivate {
|
||||
namespace media {
|
||||
class MediaExtractor;
|
||||
}
|
||||
class MediaWriter;
|
||||
}
|
||||
class _AddonManager;
|
||||
}
|
||||
|
||||
@@ -147,7 +148,7 @@ private:
|
||||
|
||||
BPrivate::_AddonManager* fEncoderMgr;
|
||||
BPrivate::_AddonManager* fWriterMgr;
|
||||
BPrivate::MediaWriter* fWriter;
|
||||
BPrivate::media::MediaWriter* fWriter;
|
||||
int32 fWriterID;
|
||||
media_file_format fMFI;
|
||||
|
||||
@@ -159,8 +160,9 @@ private:
|
||||
void _Init();
|
||||
void _UnInit();
|
||||
void _InitReader(BDataIO* source, int32 flags = 0);
|
||||
void _InitWriter(BDataIO* source,
|
||||
const media_file_format* mfi, int32 flags);
|
||||
void _InitWriter(BDataIO* target,
|
||||
const media_file_format* fileFormat,
|
||||
int32 flags);
|
||||
|
||||
BMediaFile();
|
||||
BMediaFile(const BMediaFile&);
|
||||
|
||||
@@ -217,9 +217,9 @@ private:
|
||||
|
||||
// For write-only access to a BMediaTrack
|
||||
BMediaTrack(BPrivate::media::MediaWriter* writer,
|
||||
int32 streamIndex, media_format* format,
|
||||
BPrivate::media::Encoder* encoder,
|
||||
media_codec_info* codecInfo);
|
||||
int32 streamIndex,
|
||||
const media_format* format,
|
||||
const media_codec_info* codecInfo);
|
||||
|
||||
void SetupWorkaround();
|
||||
bool SetupFormatTranslation(const media_format& from,
|
||||
|
||||
@@ -21,7 +21,8 @@ class ChunkWriter {
|
||||
public:
|
||||
virtual ~ChunkWriter() {};
|
||||
virtual status_t WriteChunk(const void* chunkBuffer,
|
||||
size_t chunkSize, uint32 flags) = 0;
|
||||
size_t chunkSize,
|
||||
media_encode_info* encodeInfo) = 0;
|
||||
};
|
||||
|
||||
|
||||
@@ -30,29 +31,42 @@ public:
|
||||
Encoder();
|
||||
virtual ~Encoder();
|
||||
|
||||
// TODO: I think we may actually need a method to specialize a
|
||||
// media_format. For example, some codecs may only support certain
|
||||
// input color spaces, or output color spaces, or multiple of 16
|
||||
// width/height... This support is technically even needed for
|
||||
// MediaFormats.h functionality, although there probably isn't
|
||||
// an application out there which uses it like that.
|
||||
// Some codecs may only support certain input color spaces, or output
|
||||
// color spaces, or multiple of 16 width/height... This method is needed
|
||||
// for get_next_encoder() functionality. If _acceptedInputFormat is NULL,
|
||||
// you simply return a status indicating if proposed format is acceptable.
|
||||
// If it contains wildcards for fields that you have restrictions on,
|
||||
// return an error. In that case, the user should be using the form of
|
||||
// get_next_encoder() that allows to specify the accepted format. If
|
||||
// _acceptedInputFormat is not NULL, copy the proposedFormat into
|
||||
// _acceptedInputFormat and specialize any wildcards. You must (!) also
|
||||
// change non-wildcard fields, like the video width if you want to round to
|
||||
// the nearest multiple of 16 for example. Only if the format is completely
|
||||
// unacceptable, return an error.
|
||||
virtual status_t AcceptedFormat(
|
||||
const media_format* proposedInputFormat,
|
||||
media_format* _acceptedInputFormat = NULL)
|
||||
= 0;
|
||||
|
||||
virtual status_t SetFormat(const media_file_format& fileFormat,
|
||||
media_format* _inOutEncodedFormat) = 0;
|
||||
// The passed media_format may not contain wildcards and must be the same
|
||||
// format that was passed to get_next_encoder() (or it must be the format
|
||||
// returned in _acceptedInputFormat).
|
||||
virtual status_t SetUp(const media_format* inputFormat) = 0;
|
||||
|
||||
virtual status_t AddTrackInfo(uint32 code, const void* data,
|
||||
size_t size, uint32 flags = 0) = 0;
|
||||
size_t size, uint32 flags = 0);
|
||||
|
||||
virtual status_t GetEncodeParameters(
|
||||
encode_parameters* parameters) const = 0;
|
||||
encode_parameters* parameters) const;
|
||||
virtual status_t SetEncodeParameters(
|
||||
encode_parameters* parameters) const = 0;
|
||||
encode_parameters* parameters) const;
|
||||
|
||||
virtual status_t Encode(const void* buffer, int64 frameCount,
|
||||
media_encode_info* info) = 0;
|
||||
|
||||
status_t WriteChunk(const void* chunkBuffer,
|
||||
size_t chunkSize, uint32 flags = 0);
|
||||
size_t chunkSize,
|
||||
media_encode_info* encodeInfo);
|
||||
|
||||
void SetChunkWriter(ChunkWriter* writer);
|
||||
|
||||
|
||||
@@ -25,22 +25,24 @@ public:
|
||||
|
||||
void GetFileFormatInfo(media_file_format* mfi) const;
|
||||
|
||||
status_t CreateEncoder(Encoder** _encoder,
|
||||
const media_codec_info* codecInfo,
|
||||
uint32 flags = 0);
|
||||
|
||||
status_t SetCopyright(int32 streamIndex,
|
||||
const char* copyright);
|
||||
status_t SetCopyright(const char* copyright);
|
||||
status_t CommitHeader();
|
||||
status_t Flush();
|
||||
status_t Close();
|
||||
|
||||
status_t AddTrackInfo(void* cookie, uint32 code,
|
||||
status_t AddTrackInfo(int32 streamIndex, uint32 code,
|
||||
const void* data, size_t size,
|
||||
uint32 flags = 0);
|
||||
|
||||
status_t CreateEncoder(Encoder** _encoder,
|
||||
const media_codec_info* codecInfo,
|
||||
uint32 flags = 0);
|
||||
|
||||
status_t WriteChunk(int32 stream,
|
||||
status_t WriteChunk(int32 streamIndex,
|
||||
const void* chunkBuffer, size_t chunkSize,
|
||||
uint32 flags);
|
||||
media_encode_info* encodeInfo);
|
||||
|
||||
private:
|
||||
struct StreamInfo {
|
||||
|
||||
@@ -21,13 +21,16 @@ public:
|
||||
virtual status_t AllocateCookie(void** cookie) = 0;
|
||||
virtual status_t FreeCookie(void* cookie) = 0;
|
||||
|
||||
virtual status_t SetCopyright(void* cookie,
|
||||
const char* copyright) = 0;
|
||||
|
||||
virtual status_t AddTrackInfo(void* cookie, uint32 code,
|
||||
const void* data, size_t size,
|
||||
uint32 flags = 0) = 0;
|
||||
|
||||
virtual status_t WriteChunk(void* cookie,
|
||||
const void* chunkBuffer, size_t chunkSize,
|
||||
uint32 flags) = 0;
|
||||
media_encode_info* encodeInfo) = 0;
|
||||
|
||||
BDataIO* Target() const;
|
||||
|
||||
|
||||
@@ -33,21 +33,31 @@ AVCodecEncoder::~AVCodecEncoder()
|
||||
|
||||
|
||||
status_t
|
||||
AVCodecEncoder::SetFormat(const media_file_format& fileFormat,
|
||||
media_format* _inOutEncodedFormat)
|
||||
AVCodecEncoder::AcceptedFormat(const media_format* proposedInputFormat,
|
||||
media_format* _acceptedInputFormat)
|
||||
{
|
||||
TRACE("AVCodecEncoder::SetFormat()\n");
|
||||
TRACE("AVCodecEncoder::AcceptedFormat(%p, %p)\n", proposedInputFormat,
|
||||
_acceptedInputFormat);
|
||||
|
||||
return B_NOT_SUPPORTED;
|
||||
if (proposedInputFormat == NULL)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
if (_acceptedInputFormat != NULL) {
|
||||
memcpy(_acceptedInputFormat, proposedInputFormat,
|
||||
sizeof(media_format));
|
||||
}
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
AVCodecEncoder::AddTrackInfo(uint32 code, const void* data, size_t size,
|
||||
uint32 flags)
|
||||
AVCodecEncoder::SetUp(const media_format* inputFormat)
|
||||
{
|
||||
TRACE("AVCodecEncoder::AddTrackInfo(%lu, %p, %ld, %lu)\n", code, data,
|
||||
size, flags);
|
||||
TRACE("AVCodecEncoder::SetUp()\n");
|
||||
|
||||
if (inputFormat == NULL)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
return B_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
@@ -17,11 +17,11 @@ public:
|
||||
|
||||
virtual ~AVCodecEncoder();
|
||||
|
||||
virtual status_t SetFormat(const media_file_format& fileFormat,
|
||||
media_format* _inOutEncodedFormat);
|
||||
virtual status_t AcceptedFormat(
|
||||
const media_format* proposedInputFormat,
|
||||
media_format* _acceptedInputFormat = NULL);
|
||||
|
||||
virtual status_t AddTrackInfo(uint32 code, const void* data,
|
||||
size_t size, uint32 flags = 0);
|
||||
virtual status_t SetUp(const media_format* inputFormat);
|
||||
|
||||
virtual status_t GetEncodeParameters(
|
||||
encode_parameters* parameters) const;
|
||||
|
||||
@@ -172,6 +172,15 @@ AVFormatWriter::FreeCookie(void* _cookie)
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
status_t
|
||||
AVFormatWriter::SetCopyright(void* cookie, const char* copyright)
|
||||
{
|
||||
TRACE("AVFormatWriter::SetCopyright(%p, %s)\n", cookie, copyright);
|
||||
|
||||
return B_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
AVFormatWriter::AddTrackInfo(void* cookie, uint32 code,
|
||||
const void* data, size_t size, uint32 flags)
|
||||
@@ -185,10 +194,10 @@ AVFormatWriter::AddTrackInfo(void* cookie, uint32 code,
|
||||
|
||||
status_t
|
||||
AVFormatWriter::WriteChunk(void* cookie, const void* chunkBuffer,
|
||||
size_t chunkSize, uint32 flags)
|
||||
size_t chunkSize, media_encode_info* encodeInfo)
|
||||
{
|
||||
TRACE("AVFormatWriter::WriteChunk(%p, %ld, %lu)\n", chunkBuffer, chunkSize,
|
||||
flags);
|
||||
TRACE("AVFormatWriter::WriteChunk(%p, %ld, %p)\n", chunkBuffer, chunkSize,
|
||||
encodeInfo);
|
||||
|
||||
return B_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
@@ -24,13 +24,16 @@ public:
|
||||
virtual status_t AllocateCookie(void** cookie);
|
||||
virtual status_t FreeCookie(void* cookie);
|
||||
|
||||
virtual status_t SetCopyright(void* cookie,
|
||||
const char* copyright);
|
||||
|
||||
virtual status_t AddTrackInfo(void* cookie, uint32 code,
|
||||
const void* data, size_t size,
|
||||
uint32 flags = 0);
|
||||
|
||||
virtual status_t WriteChunk(void* cookie,
|
||||
const void* chunkBuffer, size_t chunkSize,
|
||||
uint32 flags);
|
||||
media_encode_info* encodeInfo);
|
||||
|
||||
private:
|
||||
class StreamCookie;
|
||||
|
||||
@@ -27,9 +27,31 @@ Encoder::~Encoder()
|
||||
|
||||
|
||||
status_t
|
||||
Encoder::WriteChunk(const void* chunkBuffer, size_t chunkSize, uint32 flags)
|
||||
Encoder::AddTrackInfo(uint32 code, const void* data, size_t size, uint32 flags)
|
||||
{
|
||||
return fChunkWriter->WriteChunk(chunkBuffer, chunkSize, flags);
|
||||
return B_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
Encoder::GetEncodeParameters(encode_parameters* parameters) const
|
||||
{
|
||||
return B_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
Encoder::SetEncodeParameters(encode_parameters* parameters) const
|
||||
{
|
||||
return B_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
Encoder::WriteChunk(const void* chunkBuffer, size_t chunkSize,
|
||||
media_encode_info* encodeInfo)
|
||||
{
|
||||
return fChunkWriter->WriteChunk(chunkBuffer, chunkSize, encodeInfo);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,18 +1,23 @@
|
||||
/*
|
||||
* Copyright (c) 2002-2004, Marcus Overhagen <marcus@overhagen.de>
|
||||
* All rights reserved. Distributed under the terms of the MIT License.
|
||||
* Copyright 2009, Stephan Aßmus <superstippi@gmx.de>
|
||||
* Copyright 2002-2004, Marcus Overhagen <[email protected]>
|
||||
* All rights reserved. Distributed under the terms of the MIT license.
|
||||
*/
|
||||
|
||||
#include <MediaFile.h>
|
||||
|
||||
#include <new>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <MediaTrack.h>
|
||||
#include <File.h>
|
||||
#include <MediaTrack.h>
|
||||
|
||||
#include "debug.h"
|
||||
|
||||
#include "MediaExtractor.h"
|
||||
#include "debug.h"
|
||||
#include "MediaWriter.h"
|
||||
|
||||
|
||||
BMediaFile::BMediaFile(const entry_ref* ref)
|
||||
@@ -213,11 +218,32 @@ BMediaFile::ReleaseAllTracks()
|
||||
|
||||
// Create and add a track to the media file
|
||||
BMediaTrack*
|
||||
BMediaFile::CreateTrack(media_format* mf, const media_codec_info* mci,
|
||||
uint32 flags)
|
||||
BMediaFile::CreateTrack(media_format* mediaFormat,
|
||||
const media_codec_info* codecInfo, uint32 flags)
|
||||
{
|
||||
UNIMPLEMENTED();
|
||||
return 0;
|
||||
if (mediaFormat == NULL)
|
||||
return NULL;
|
||||
|
||||
// NOTE: It is allowed to pass NULL for codecInfo. In that case, the
|
||||
// track won't have an Encoder and you can only use WriteChunk() with
|
||||
// already encoded data.
|
||||
|
||||
// Make room for the new track.
|
||||
BMediaTrack** trackList = (BMediaTrack**)realloc(fTrackList,
|
||||
(fTrackNum + 1) * sizeof(BMediaTrack*));
|
||||
if (trackList == NULL)
|
||||
return NULL;
|
||||
|
||||
int32 streamIndex = fTrackNum;
|
||||
fTrackList = trackList;
|
||||
fTrackNum += 1;
|
||||
|
||||
BMediaTrack* track = new(std::nothrow) BMediaTrack(fWriter, streamIndex,
|
||||
mediaFormat, codecInfo);
|
||||
|
||||
fTrackList[streamIndex] = track;
|
||||
|
||||
return track;
|
||||
}
|
||||
|
||||
|
||||
@@ -253,10 +279,12 @@ CreateTrack__10BMediaFileP12media_format(BMediaFile* self, media_format* mf)
|
||||
|
||||
// Lets you set the copyright info for the entire file
|
||||
status_t
|
||||
BMediaFile::AddCopyright(const char* data)
|
||||
BMediaFile::AddCopyright(const char* copyright)
|
||||
{
|
||||
UNIMPLEMENTED();
|
||||
return B_OK;
|
||||
if (fWriter == NULL)
|
||||
return B_NO_INIT;
|
||||
|
||||
return fWriter->SetCopyright(copyright);
|
||||
}
|
||||
|
||||
|
||||
@@ -273,8 +301,10 @@ BMediaFile::AddChunk(int32 type, const void* data, size_t size)
|
||||
status_t
|
||||
BMediaFile::CommitHeader()
|
||||
{
|
||||
UNIMPLEMENTED();
|
||||
return B_OK;
|
||||
if (fWriter == NULL)
|
||||
return B_NO_INIT;
|
||||
|
||||
return fWriter->CommitHeader();
|
||||
}
|
||||
|
||||
|
||||
@@ -282,8 +312,10 @@ BMediaFile::CommitHeader()
|
||||
status_t
|
||||
BMediaFile::CloseFile()
|
||||
{
|
||||
UNIMPLEMENTED();
|
||||
return B_OK;
|
||||
if (fWriter == NULL)
|
||||
return B_NO_INIT;
|
||||
|
||||
return fWriter->Close();
|
||||
}
|
||||
|
||||
// This is for controlling file format parameters
|
||||
@@ -374,7 +406,7 @@ void
|
||||
BMediaFile::_UnInit()
|
||||
{
|
||||
ReleaseAllTracks();
|
||||
delete[] fTrackList;
|
||||
free(fTrackList);
|
||||
fTrackList = NULL;
|
||||
fTrackNum = 0;
|
||||
delete fExtractor;
|
||||
@@ -409,7 +441,7 @@ BMediaFile::_InitReader(BDataIO* source, int32 flags)
|
||||
|
||||
fExtractor->GetFileFormatInfo(&fMFI);
|
||||
fTrackNum = fExtractor->StreamCount();
|
||||
fTrackList = new (std::nothrow) BMediaTrack*[fTrackNum];
|
||||
fTrackList = (BMediaTrack**)malloc(fTrackNum * sizeof(BMediaTrack*));
|
||||
if (fTrackList == NULL) {
|
||||
fErr = B_NO_MEMORY;
|
||||
return;
|
||||
@@ -419,12 +451,33 @@ BMediaFile::_InitReader(BDataIO* source, int32 flags)
|
||||
|
||||
|
||||
void
|
||||
BMediaFile::_InitWriter(BDataIO* source, const media_file_format* mfi,
|
||||
BMediaFile::_InitWriter(BDataIO* target, const media_file_format* fileFormat,
|
||||
int32 flags)
|
||||
{
|
||||
UNIMPLEMENTED();
|
||||
fSource = source;
|
||||
fErr = B_NOT_ALLOWED;
|
||||
CALLED();
|
||||
|
||||
if (fileFormat == NULL) {
|
||||
fErr = B_BAD_VALUE;
|
||||
return;
|
||||
}
|
||||
|
||||
if (target == NULL) {
|
||||
fErr = B_NO_MEMORY;
|
||||
return;
|
||||
}
|
||||
|
||||
fMFI = *fileFormat;
|
||||
fSource = target;
|
||||
|
||||
fWriter = new(std::nothrow) MediaWriter(fSource, fMFI);
|
||||
if (fWriter == NULL)
|
||||
fErr = B_NO_MEMORY;
|
||||
else
|
||||
fErr = fWriter->InitCheck();
|
||||
if (fErr != B_OK)
|
||||
return;
|
||||
|
||||
fTrackNum = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,37 +1,26 @@
|
||||
/*
|
||||
* Copyright (c) 2002-2007, Marcus Overhagen <marcus@overhagen.de>
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
* Copyright 2009, Stephan Aßmus <superstippi@gmx.de>
|
||||
* Copyright 2002-2007, Marcus Overhagen <marcus@overhagen.de>
|
||||
* All rights reserved. Distributed under the terms of the MIT license.
|
||||
*/
|
||||
|
||||
|
||||
#include <MediaTrack.h>
|
||||
#include <Roster.h>
|
||||
|
||||
#include <new>
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <new>
|
||||
#include "MediaExtractor.h"
|
||||
#include "PluginManager.h"
|
||||
|
||||
#include <Roster.h>
|
||||
|
||||
#include "debug.h"
|
||||
|
||||
#include "MediaExtractor.h"
|
||||
#include "MediaWriter.h"
|
||||
#include "PluginManager.h"
|
||||
|
||||
|
||||
//#define TRACE_MEDIA_TRACK
|
||||
#ifdef TRACE_MEDIA_TRACK
|
||||
#ifndef TRACE
|
||||
@@ -525,76 +514,74 @@ BMediaTrack::ReadChunk(char **out_buffer,
|
||||
|
||||
|
||||
status_t
|
||||
BMediaTrack::AddCopyright(const char *data)
|
||||
BMediaTrack::AddCopyright(const char* copyright)
|
||||
{
|
||||
UNIMPLEMENTED();
|
||||
if (fWriter == NULL)
|
||||
return B_NO_INIT;
|
||||
|
||||
return B_OK;
|
||||
return fWriter->SetCopyright(fStream, copyright);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BMediaTrack::AddTrackInfo(uint32 code,
|
||||
const void *data,
|
||||
size_t size,
|
||||
BMediaTrack::AddTrackInfo(uint32 code, const void* data, size_t size,
|
||||
uint32 flags)
|
||||
{
|
||||
UNIMPLEMENTED();
|
||||
if (fWriter == NULL)
|
||||
return B_NO_INIT;
|
||||
|
||||
return B_OK;
|
||||
return fWriter->AddTrackInfo(fStream, code, data, size, flags);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BMediaTrack::WriteFrames(const void *data,
|
||||
int32 num_frames,
|
||||
int32 flags)
|
||||
BMediaTrack::WriteFrames(const void* data, int32 frameCount, int32 flags)
|
||||
{
|
||||
UNIMPLEMENTED();
|
||||
media_encode_info encodeInfo;
|
||||
encodeInfo.flags = flags;
|
||||
|
||||
return B_OK;
|
||||
return WriteFrames(data, frameCount, &encodeInfo);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BMediaTrack::WriteFrames(const void *data,
|
||||
int64 num_frames,
|
||||
BMediaTrack::WriteFrames(const void* data, int64 frameCount,
|
||||
media_encode_info* info)
|
||||
{
|
||||
UNIMPLEMENTED();
|
||||
if (fEncoder == NULL)
|
||||
return B_NO_INIT;
|
||||
|
||||
return B_OK;
|
||||
return fEncoder->Encode(data, frameCount, info);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BMediaTrack::WriteChunk(const void *data,
|
||||
size_t size,
|
||||
uint32 flags)
|
||||
BMediaTrack::WriteChunk(const void* data, size_t size, uint32 flags)
|
||||
{
|
||||
UNIMPLEMENTED();
|
||||
media_encode_info encodeInfo;
|
||||
encodeInfo.flags = flags;
|
||||
|
||||
return B_OK;
|
||||
return WriteChunk(data, size, &encodeInfo);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BMediaTrack::WriteChunk(const void *data,
|
||||
size_t size,
|
||||
media_encode_info *info)
|
||||
BMediaTrack::WriteChunk(const void* data, size_t size, media_encode_info* info)
|
||||
{
|
||||
UNIMPLEMENTED();
|
||||
if (fWriter == NULL)
|
||||
return B_NO_INIT;
|
||||
|
||||
return B_OK;
|
||||
return fWriter->WriteChunk(fStream, data, size, info);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BMediaTrack::Flush()
|
||||
{
|
||||
UNIMPLEMENTED();
|
||||
if (fWriter == NULL)
|
||||
return B_NO_INIT;
|
||||
|
||||
return B_OK;
|
||||
return fWriter->Flush();
|
||||
}
|
||||
|
||||
|
||||
@@ -713,9 +700,8 @@ BMediaTrack::BMediaTrack(BPrivate::media::MediaExtractor *extractor,
|
||||
if (ret != B_OK) {
|
||||
TRACE("BMediaTrack::BMediaTrack: Error: creating decoder failed: "
|
||||
"%s\n", strerror(ret));
|
||||
// we do not set fErr here, because ReadChunk should still work
|
||||
// We do not set fErr here, because ReadChunk should still work.
|
||||
fDecoder = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
fCurFrame = 0;
|
||||
@@ -729,12 +715,41 @@ BMediaTrack::BMediaTrack(BPrivate::media::MediaExtractor *extractor,
|
||||
|
||||
|
||||
BMediaTrack::BMediaTrack(BPrivate::media::MediaWriter* writer,
|
||||
int32 stream_num,
|
||||
media_format *in_format,
|
||||
BPrivate::media::Encoder *encoder,
|
||||
media_codec_info *mci)
|
||||
int32 streamIndex, const media_format* format,
|
||||
const media_codec_info* codecInfo)
|
||||
{
|
||||
UNIMPLEMENTED();
|
||||
CALLED();
|
||||
|
||||
fWorkaroundFlags = 0;
|
||||
fEncoder = NULL;
|
||||
fEncoderID = -1;
|
||||
// TODO: Not yet sure what this was needed for...
|
||||
fWriter = writer;
|
||||
fWriterFormat = *format;
|
||||
fStream = streamIndex;
|
||||
fErr = B_OK;
|
||||
|
||||
SetupWorkaround();
|
||||
|
||||
if (codecInfo != NULL) {
|
||||
status_t ret = fWriter->CreateEncoder(&fEncoder, codecInfo);
|
||||
if (ret != B_OK) {
|
||||
TRACE("BMediaTrack::BMediaTrack: Error: creating decoder failed: "
|
||||
"%s\n", strerror(ret));
|
||||
// We do not set fErr here, because WriteChunk should still work.
|
||||
fEncoder = NULL;
|
||||
} else {
|
||||
fMCI = *codecInfo;
|
||||
fErr = fEncoder->SetUp(&fWriterFormat);
|
||||
}
|
||||
}
|
||||
|
||||
// not used:
|
||||
fCurFrame = 0;
|
||||
fCurTime = 0;
|
||||
fDecoder = NULL;
|
||||
fRawDecoder = NULL;
|
||||
fExtractor = NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -756,7 +771,8 @@ BMediaTrack::SetupWorkaround()
|
||||
be_roster->GetRunningAppInfo(tinfo.team, &ainfo);
|
||||
|
||||
if (strcmp(ainfo.signature, "application/x-vnd.marcone-soundplay") == 0) {
|
||||
fWorkaroundFlags = FORCE_RAW_AUDIO | FORCE_RAW_AUDIO_INT16_FORMAT | FORCE_RAW_AUDIO_HOST_ENDIAN;
|
||||
fWorkaroundFlags = FORCE_RAW_AUDIO | FORCE_RAW_AUDIO_INT16_FORMAT
|
||||
| FORCE_RAW_AUDIO_HOST_ENDIAN;
|
||||
printf("BMediaTrack::SetupWorkaround: SoundPlay workaround active\n");
|
||||
}
|
||||
if (strcmp(ainfo.signature, "application/x-vnd.Be.MediaPlayer") == 0) {
|
||||
@@ -770,6 +786,7 @@ BMediaTrack::SetupWorkaround()
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
BMediaTrack::SetupFormatTranslation(const media_format &from, media_format *to)
|
||||
{
|
||||
@@ -790,12 +807,16 @@ BMediaTrack::SetupFormatTranslation(const media_format &from, media_format *to)
|
||||
|
||||
// XXX video?
|
||||
int buffer_size = from.u.raw_audio.buffer_size;
|
||||
int frame_size = (from.u.raw_audio.format & 15) * from.u.raw_audio.channel_count;
|
||||
int frame_size = (from.u.raw_audio.format & 15)
|
||||
* from.u.raw_audio.channel_count;
|
||||
media_format notconstFrom = from;
|
||||
|
||||
ChunkProvider *chunkProvider = new(std::nothrow) RawDecoderChunkProvider(fDecoder, buffer_size, frame_size);
|
||||
ChunkProvider *chunkProvider
|
||||
= new(std::nothrow) RawDecoderChunkProvider(fDecoder, buffer_size,
|
||||
frame_size);
|
||||
if (!chunkProvider) {
|
||||
ERROR("BMediaTrack::SetupFormatTranslation: can't create chunk provider\n");
|
||||
ERROR("BMediaTrack::SetupFormatTranslation: can't create chunk "
|
||||
"provider\n");
|
||||
goto error;
|
||||
}
|
||||
fRawDecoder->SetChunkProvider(chunkProvider);
|
||||
@@ -813,7 +834,8 @@ BMediaTrack::SetupFormatTranslation(const media_format &from, media_format *to)
|
||||
|
||||
res = fRawDecoder->NegotiateOutputFormat(to);
|
||||
if (res != B_OK) {
|
||||
ERROR("BMediaTrack::SetupFormatTranslation: NegotiateOutputFormat failed\n");
|
||||
ERROR("BMediaTrack::SetupFormatTranslation: NegotiateOutputFormat "
|
||||
"failed\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
||||
+112
-37
@@ -18,6 +18,32 @@
|
||||
#include "PluginManager.h"
|
||||
|
||||
|
||||
|
||||
class MediaExtractorChunkWriter : public ChunkWriter {
|
||||
public:
|
||||
MediaExtractorChunkWriter(MediaWriter* writer, int32 streamIndex)
|
||||
:
|
||||
fWriter(writer),
|
||||
fStreamIndex(streamIndex)
|
||||
{
|
||||
}
|
||||
|
||||
virtual status_t WriteChunk(const void* chunkBuffer, size_t chunkSize,
|
||||
media_encode_info* encodeInfo)
|
||||
{
|
||||
return fWriter->WriteChunk(fStreamIndex, chunkBuffer, chunkSize,
|
||||
encodeInfo);
|
||||
}
|
||||
|
||||
private:
|
||||
MediaWriter* fWriter;
|
||||
int32 fStreamIndex;
|
||||
};
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
MediaWriter::MediaWriter(BDataIO* target, const media_file_format& fileFormat)
|
||||
:
|
||||
fTarget(target),
|
||||
@@ -66,43 +92,6 @@ MediaWriter::GetFileFormatInfo(media_file_format* _fileFormat) const
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
MediaWriter::WriteChunk(int32 streamIndex, const void* chunkBuffer,
|
||||
size_t chunkSize, uint32 flags)
|
||||
{
|
||||
if (fWriter == NULL)
|
||||
return B_NO_INIT;
|
||||
|
||||
StreamInfo* info;
|
||||
if (!fStreamInfos.Get(streamIndex, &info))
|
||||
return B_BAD_INDEX;
|
||||
|
||||
return fWriter->WriteChunk(info->cookie, chunkBuffer, chunkSize, flags);
|
||||
}
|
||||
|
||||
|
||||
class MediaExtractorChunkWriter : public ChunkWriter {
|
||||
public:
|
||||
MediaExtractorChunkWriter(MediaWriter* writer, int32 streamIndex)
|
||||
:
|
||||
fWriter(writer),
|
||||
fStreamIndex(streamIndex)
|
||||
{
|
||||
}
|
||||
|
||||
virtual status_t WriteChunk(const void* chunkBuffer, size_t chunkSize,
|
||||
uint32 flags)
|
||||
{
|
||||
return fWriter->WriteChunk(fStreamIndex, chunkBuffer, chunkSize,
|
||||
flags);
|
||||
}
|
||||
|
||||
private:
|
||||
MediaWriter* fWriter;
|
||||
int32 fStreamIndex;
|
||||
};
|
||||
|
||||
|
||||
status_t
|
||||
MediaWriter::CreateEncoder(Encoder** _encoder,
|
||||
const media_codec_info* codecInfo, uint32 flags)
|
||||
@@ -149,3 +138,89 @@ MediaWriter::CreateEncoder(Encoder** _encoder,
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
MediaWriter::SetCopyright(const char* copyright)
|
||||
{
|
||||
if (fWriter == NULL)
|
||||
return B_NO_INIT;
|
||||
|
||||
return fWriter->SetCopyright(copyright);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
MediaWriter::SetCopyright(int32 streamIndex, const char* copyright)
|
||||
{
|
||||
if (fWriter == NULL)
|
||||
return B_NO_INIT;
|
||||
|
||||
StreamInfo* info;
|
||||
if (!fStreamInfos.Get(streamIndex, &info))
|
||||
return B_BAD_INDEX;
|
||||
|
||||
return fWriter->SetCopyright(info->cookie, copyright);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
MediaWriter::CommitHeader()
|
||||
{
|
||||
if (fWriter == NULL)
|
||||
return B_NO_INIT;
|
||||
|
||||
return fWriter->CommitHeader();
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
MediaWriter::Flush()
|
||||
{
|
||||
if (fWriter == NULL)
|
||||
return B_NO_INIT;
|
||||
|
||||
return fWriter->Flush();
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
MediaWriter::Close()
|
||||
{
|
||||
if (fWriter == NULL)
|
||||
return B_NO_INIT;
|
||||
|
||||
return fWriter->Close();
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
MediaWriter::AddTrackInfo(int32 streamIndex, uint32 code,
|
||||
const void* data, size_t size, uint32 flags)
|
||||
{
|
||||
if (fWriter == NULL)
|
||||
return B_NO_INIT;
|
||||
|
||||
StreamInfo* info;
|
||||
if (!fStreamInfos.Get(streamIndex, &info))
|
||||
return B_BAD_INDEX;
|
||||
|
||||
return fWriter->AddTrackInfo(info->cookie, code, data, size, flags);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
MediaWriter::WriteChunk(int32 streamIndex, const void* chunkBuffer,
|
||||
size_t chunkSize, media_encode_info* encodeInfo)
|
||||
{
|
||||
if (fWriter == NULL)
|
||||
return B_NO_INIT;
|
||||
|
||||
StreamInfo* info;
|
||||
if (!fStreamInfos.Get(streamIndex, &info))
|
||||
return B_BAD_INDEX;
|
||||
|
||||
return fWriter->WriteChunk(info->cookie, chunkBuffer, chunkSize,
|
||||
encodeInfo);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user