fixed for connecting and crashing bugs.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1055 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
2a6deaf6c4
commit
8811eeb6aa
@ -3,6 +3,8 @@ SubDir OBOS_TOP src add-ons media media-add-ons writer ;
|
||||
UsePrivateHeaders media ;
|
||||
|
||||
Addon writer.media_addon : media :
|
||||
../AbstractFileInterfaceNode.cpp
|
||||
../AbstractFileInterfaceAddOn.cpp
|
||||
MediaWriter.cpp
|
||||
MediaWriterAddOn.cpp
|
||||
;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -23,11 +23,11 @@
|
||||
#include <Entry.h>
|
||||
#include <BufferGroup.h>
|
||||
|
||||
#include "../AbstractFileInterfaceNode.h"
|
||||
|
||||
class MediaWriter :
|
||||
public BFileInterface,
|
||||
public BBufferConsumer,
|
||||
public BControllable,
|
||||
public BMediaEventLooper
|
||||
public AbstractFileInterfaceNode
|
||||
{
|
||||
protected:
|
||||
virtual ~MediaWriter(void);
|
||||
@ -41,43 +41,15 @@ explicit MediaWriter(
|
||||
BMessage * config = 0,
|
||||
BMediaAddOn * addOn = 0);
|
||||
|
||||
virtual status_t InitCheck(void) const;
|
||||
|
||||
// see BMediaAddOn::GetConfigurationFor
|
||||
virtual status_t GetConfigurationFor(
|
||||
BMessage * into_message);
|
||||
|
||||
/*************************/
|
||||
/* begin from BMediaNode */
|
||||
public:
|
||||
// /* this port is what a media node listens to for commands */
|
||||
// virtual port_id ControlPort(void) const;
|
||||
|
||||
virtual BMediaAddOn* AddOn(
|
||||
int32 * internal_id) const; /* Who instantiated you -- or NULL for app class */
|
||||
|
||||
protected:
|
||||
/* These don't return errors; instead, they use the global error condition reporter. */
|
||||
/* A node is required to have a queue of at least one pending command (plus TimeWarp) */
|
||||
/* and is recommended to allow for at least one pending command of each type. */
|
||||
/* Allowing an arbitrary number of outstanding commands might be nice, but apps */
|
||||
/* cannot depend on that happening. */
|
||||
virtual void Start(
|
||||
bigtime_t performance_time);
|
||||
virtual void Stop(
|
||||
bigtime_t performance_time,
|
||||
bool immediate);
|
||||
virtual void Seek(
|
||||
bigtime_t media_time,
|
||||
bigtime_t performance_time);
|
||||
virtual void SetRunMode(
|
||||
run_mode mode);
|
||||
virtual void TimeWarp(
|
||||
bigtime_t at_real_time,
|
||||
bigtime_t to_performance_time);
|
||||
virtual void Preroll(void);
|
||||
virtual void SetTimeSource(
|
||||
BTimeSource * time_source);
|
||||
|
||||
public:
|
||||
virtual status_t HandleMessage(
|
||||
@ -86,62 +58,18 @@ virtual status_t HandleMessage(
|
||||
size_t size);
|
||||
|
||||
protected:
|
||||
/* Called when requests have completed, or failed. */
|
||||
virtual status_t RequestCompleted( /* reserved 0 */
|
||||
const media_request_info & info);
|
||||
|
||||
protected:
|
||||
virtual status_t DeleteHook(BMediaNode * node); /* reserved 1 */
|
||||
|
||||
virtual void NodeRegistered(void); /* reserved 2 */
|
||||
|
||||
public:
|
||||
|
||||
/* fill out your attributes in the provided array, returning however many you have. */
|
||||
virtual status_t GetNodeAttributes( /* reserved 3 */
|
||||
media_node_attribute * outAttributes,
|
||||
size_t inMaxCount);
|
||||
|
||||
virtual status_t AddTimer(
|
||||
bigtime_t at_performance_time,
|
||||
int32 cookie);
|
||||
|
||||
/* end from BMediaNode */
|
||||
/***********************/
|
||||
|
||||
protected:
|
||||
virtual BParameterWeb * MakeParameterWeb(void);
|
||||
|
||||
/*****************************/
|
||||
/* begin from BFileInterface */
|
||||
protected:
|
||||
//included from BMediaNode
|
||||
//virtual status_t HandleMessage(
|
||||
// int32 message,
|
||||
// const void * data,
|
||||
// size_t size);
|
||||
|
||||
virtual status_t GetNextFileFormat(
|
||||
int32 * cookie,
|
||||
media_file_format * out_format);
|
||||
virtual void DisposeFileFormatCookie(
|
||||
int32 cookie);
|
||||
|
||||
virtual status_t GetDuration(
|
||||
bigtime_t * out_time);
|
||||
|
||||
virtual status_t SniffRef(
|
||||
const entry_ref & file,
|
||||
char * out_mime_type, /* 256 bytes */
|
||||
float * out_quality);
|
||||
|
||||
virtual status_t SetRef(
|
||||
const entry_ref & file,
|
||||
bool create,
|
||||
bigtime_t * out_time);
|
||||
virtual status_t GetRef(
|
||||
entry_ref * out_ref,
|
||||
char * out_mime_type);
|
||||
|
||||
/* end from BFileInterface */
|
||||
/***************************/
|
||||
@ -215,78 +143,13 @@ virtual status_t SeekTagRequested(
|
||||
/* end from BBufferConsumer */
|
||||
/****************************/
|
||||
|
||||
/****************************/
|
||||
/* begin from BControllable */
|
||||
/*****************/
|
||||
/* BControllable */
|
||||
/*****************/
|
||||
|
||||
//included from BMediaNode
|
||||
//virtual status_t HandleMessage(
|
||||
// int32 message,
|
||||
// const void * data,
|
||||
// size_t size);
|
||||
public:
|
||||
/* These are alternate methods of accomplishing the same thing as */
|
||||
/* connecting to control information source/destinations would. */
|
||||
virtual status_t GetParameterValue(
|
||||
int32 id,
|
||||
bigtime_t * last_change,
|
||||
void * value,
|
||||
size_t * ioSize);
|
||||
virtual void SetParameterValue(
|
||||
int32 id,
|
||||
bigtime_t when,
|
||||
const void * value,
|
||||
size_t size);
|
||||
virtual status_t StartControlPanel(
|
||||
BMessenger * out_messenger);
|
||||
|
||||
/* end from BControllable */
|
||||
/**************************/
|
||||
|
||||
public:
|
||||
// these three are related:
|
||||
// DEFAULT_CHUNK_SIZE = (DEFAULT_BIT_RATE * 1024) * (DEFAULT_BUFFER_PERIOD / 8000000)
|
||||
static const int32 DEFAULT_CHUNK_SIZE_PARAM; // in bytes
|
||||
static const int32 DEFAULT_BIT_RATE_PARAM; // in 1000*kilobits/sec
|
||||
static const int32 DEFAULT_BUFFER_PERIOD_PARAM; // milliseconds
|
||||
|
||||
private:
|
||||
size_t defaultChunkSizeParam;
|
||||
bigtime_t defaultChunkSizeParamChangeTime;
|
||||
float defaultBitRateParam;
|
||||
bigtime_t defaultBitRateParamChangeTime;
|
||||
bigtime_t defaultBufferPeriodParam;
|
||||
bigtime_t defaultBufferPeriodParamChangeTime;
|
||||
|
||||
// This is used to figure out which parameter to compute
|
||||
// when enforcing the above constraint relating the three params
|
||||
int32 lastUpdatedParameter;
|
||||
int32 leastRecentlyUpdatedParameter;
|
||||
|
||||
/********************************/
|
||||
/* start from BMediaEventLooper */
|
||||
|
||||
protected:
|
||||
/* you must override to handle your events! */
|
||||
/* you should not call HandleEvent directly */
|
||||
virtual void HandleEvent( const media_timed_event *event,
|
||||
bigtime_t lateness,
|
||||
bool realTimeEvent = false);
|
||||
|
||||
/* override to clean up custom events you have added to your queue */
|
||||
virtual void CleanUpEvent(const media_timed_event *event);
|
||||
|
||||
/* called from Offline mode to determine the current time of the node */
|
||||
/* update your internal information whenever it changes */
|
||||
virtual bigtime_t OfflineTime();
|
||||
|
||||
/* override only if you know what you are doing! */
|
||||
/* otherwise much badness could occur */
|
||||
/* the actual control loop function: */
|
||||
/* waits for messages, Pops events off the queue and calls DispatchEvent */
|
||||
virtual void ControlLoop();
|
||||
|
||||
/* end from BMediaEventLooper */
|
||||
/******************************/
|
||||
/*********************/
|
||||
/* BMediaEventLooper */
|
||||
/*********************/
|
||||
|
||||
protected:
|
||||
|
||||
@ -294,24 +157,20 @@ virtual status_t HandleBuffer(
|
||||
const media_timed_event *event,
|
||||
bigtime_t lateness,
|
||||
bool realTimeEvent = false);
|
||||
|
||||
virtual status_t HandleParameter(
|
||||
virtual status_t HandleDataStatus(
|
||||
const media_timed_event *event,
|
||||
bigtime_t lateness,
|
||||
bool realTimeEvent = false);
|
||||
|
||||
public:
|
||||
|
||||
static status_t GetFlavor(int32 id, const flavor_info ** out_info);
|
||||
static media_format & GetFormat();
|
||||
static media_file_format & GetFileFormat();
|
||||
static void GetFlavor(flavor_info * info, int32 id);
|
||||
static media_format * GetFormat();
|
||||
static media_file_format * GetFileFormat();
|
||||
|
||||
protected:
|
||||
|
||||
virtual status_t ResetFormat(media_format * format);
|
||||
virtual status_t ResolveWildcards(media_multistream_format * multistream_format);
|
||||
virtual status_t GetFilledBuffer(BBuffer ** outBuffer);
|
||||
virtual status_t FillFileBuffer(BBuffer * buffer);
|
||||
virtual status_t WriteFileBuffer(BBuffer * buffer);
|
||||
|
||||
private:
|
||||
|
||||
@ -320,25 +179,16 @@ private:
|
||||
MediaWriter & operator=(
|
||||
const MediaWriter & clone);
|
||||
|
||||
status_t initCheckStatus;
|
||||
|
||||
BMediaAddOn * mediaWriterAddOn;
|
||||
media_input input;
|
||||
|
||||
BFile * outputFile;
|
||||
entry_ref output_ref;
|
||||
char output_mime_type[B_MIME_TYPE_LENGTH+1];
|
||||
|
||||
BBufferGroup * bufferGroup;
|
||||
|
||||
bigtime_t downstreamLatency;
|
||||
bigtime_t internalLatency;
|
||||
|
||||
bool intputEnabled;
|
||||
bool fInputEnabled;
|
||||
|
||||
BBufferGroup * fBufferGroup;
|
||||
bigtime_t fDownstreamLatency;
|
||||
bigtime_t fInternalLatency;
|
||||
// this is computed from the real (negotiated) chunk size and bit rate,
|
||||
// not the defaults that are in the parameters
|
||||
bigtime_t bufferPeriod;
|
||||
bigtime_t fBufferPeriod;
|
||||
|
||||
/* Mmmh, stuffing! */
|
||||
virtual status_t _Reserved_MediaWriter_0(void *);
|
||||
|
@ -36,29 +36,15 @@ MediaWriterAddOn::~MediaWriterAddOn()
|
||||
}
|
||||
|
||||
MediaWriterAddOn::MediaWriterAddOn(image_id image) :
|
||||
BMediaAddOn(image)
|
||||
AbstractFileInterfaceAddOn(image)
|
||||
{
|
||||
fprintf(stderr,"MediaWriterAddOn::MediaWriterAddOn\n");
|
||||
refCount = 0;
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------------------------- //
|
||||
// BMediaAddOn impl
|
||||
// -------------------------------------------------------- //
|
||||
|
||||
status_t MediaWriterAddOn::InitCheck(
|
||||
const char ** out_failure_text)
|
||||
{
|
||||
fprintf(stderr,"MediaWriterAddOn::InitCheck\n");
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
int32 MediaWriterAddOn::CountFlavors()
|
||||
{
|
||||
fprintf(stderr,"MediaWriterAddOn::CountFlavors\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
status_t MediaWriterAddOn::GetFlavorAt(
|
||||
int32 n,
|
||||
const flavor_info ** out_info)
|
||||
@ -72,7 +58,10 @@ status_t MediaWriterAddOn::GetFlavorAt(
|
||||
fprintf(stderr,"<- B_BAD_INDEX\n");
|
||||
return B_BAD_INDEX;
|
||||
}
|
||||
return MediaWriter::GetFlavor(n,out_info);
|
||||
flavor_info * infos = new flavor_info[1];
|
||||
MediaWriter::GetFlavor(&infos[0],n);
|
||||
(*out_info) = infos;
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
BMediaNode * MediaWriterAddOn::InstantiateNodeFor(
|
||||
@ -87,9 +76,10 @@ BMediaNode * MediaWriterAddOn::InstantiateNodeFor(
|
||||
}
|
||||
size_t defaultChunkSize = size_t(8192); // XXX: read from add-on's attributes
|
||||
float defaultBitRate = 800000;
|
||||
MediaWriter * node = new MediaWriter(defaultChunkSize,
|
||||
defaultBitRate,
|
||||
info,config,this);
|
||||
MediaWriter * node
|
||||
= new MediaWriter(defaultChunkSize,
|
||||
defaultBitRate,
|
||||
info,config,this);
|
||||
if (node == 0) {
|
||||
*out_error = B_NO_MEMORY;
|
||||
fprintf(stderr,"<- B_NO_MEMORY\n");
|
||||
@ -108,7 +98,8 @@ status_t MediaWriterAddOn::GetConfigurationFor(
|
||||
fprintf(stderr,"<- B_BAD_VALUE\n");
|
||||
return B_BAD_VALUE; // we refuse to crash because you were stupid
|
||||
}
|
||||
MediaWriter * node = dynamic_cast<MediaWriter*>(your_node);
|
||||
MediaWriter * node
|
||||
= dynamic_cast<MediaWriter*>(your_node);
|
||||
if (node == 0) {
|
||||
fprintf(stderr,"<- B_BAD_TYPE\n");
|
||||
return B_BAD_TYPE;
|
||||
@ -116,66 +107,18 @@ status_t MediaWriterAddOn::GetConfigurationFor(
|
||||
return node->GetConfigurationFor(into_message);
|
||||
}
|
||||
|
||||
bool MediaWriterAddOn::WantsAutoStart()
|
||||
{
|
||||
fprintf(stderr,"MediaWriterAddOn::WantsAutoStart\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
status_t MediaWriterAddOn::AutoStart(
|
||||
int in_count,
|
||||
BMediaNode ** out_node,
|
||||
int32 * out_internal_id,
|
||||
bool * out_has_more)
|
||||
{
|
||||
fprintf(stderr,"MediaWriterAddOn::AutoStart\n");
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------- //
|
||||
// BMediaAddOn impl for B_FILE_INTERFACE nodes
|
||||
// -------------------------------------------------------- //
|
||||
|
||||
status_t MediaWriterAddOn::SniffRef(
|
||||
const entry_ref & file,
|
||||
BMimeType * io_mime_type,
|
||||
float * out_quality,
|
||||
int32 * out_internal_id)
|
||||
{
|
||||
fprintf(stderr,"MediaWriterAddOn::SniffRef\n");
|
||||
if ((io_mime_type == 0) || (out_quality == 0) || (out_internal_id == 0)) {
|
||||
fprintf(stderr,"<- B_BAD_VALUE\n");
|
||||
return B_BAD_VALUE; // we refuse to crash because you were stupid
|
||||
}
|
||||
*out_internal_id = 0; // only one flavor
|
||||
char mime_string[B_MIME_TYPE_LENGTH+1];
|
||||
status_t status = MediaWriter::StaticSniffRef(file,mime_string,out_quality);
|
||||
io_mime_type->SetTo(mime_string);
|
||||
return status;
|
||||
}
|
||||
|
||||
// even though I implemented SniffTypeKind below and this shouldn't get called,
|
||||
// I am going to implement it anyway. I'll use it later anyhow.
|
||||
status_t MediaWriterAddOn::SniffType(
|
||||
const BMimeType & type,
|
||||
float * out_quality,
|
||||
int32 * out_internal_id)
|
||||
{
|
||||
fprintf(stderr,"MediaWriterAddOn::SniffType\n");
|
||||
if ((out_quality == 0) || (out_internal_id == 0)) {
|
||||
fprintf(stderr,"<- B_BAD_VALUE\n");
|
||||
return B_BAD_VALUE; // we refuse to crash because you were stupid
|
||||
}
|
||||
*out_quality = 1.0;
|
||||
*out_internal_id = 0;
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
// This function treats null pointers slightly differently than the others.
|
||||
// This is because a program could reasonably call this function with just
|
||||
// about any junk, get the out_read_items and then use that to create an
|
||||
// array of sufficient size to hold the result, and then recall. Also, a
|
||||
// stupid program could not supply an out_read_items, but actually supply
|
||||
// about any junk, get the out_read_items or out_write_items and then use
|
||||
// that to create an array of sufficient size to hold the result, and then
|
||||
// call us again. So we won't punish them if they supply us with null
|
||||
// pointers the first time around.
|
||||
//
|
||||
// A stupid program might not supply an out_read_items, but actually supply
|
||||
// an out_readable_formats and then try to do something useful with it. As
|
||||
// an extreme gesture of nicety we will fill the out_readable_formats with
|
||||
// a valid entry, although they could easily read into garbage after that...
|
||||
@ -203,11 +146,10 @@ status_t MediaWriterAddOn::GetFileFormatList(
|
||||
if (out_read_items != 0) {
|
||||
*out_read_items = 1;
|
||||
}
|
||||
// see null check comment above
|
||||
if (out_readable_formats != 0) {
|
||||
// don't go off the end
|
||||
if (in_read_items > 0) {
|
||||
out_readable_formats[0] = MediaWriter::GetFileFormat();
|
||||
if (in_write_items > 0) {
|
||||
out_writable_formats[0] = *MediaWriter::GetFileFormat();
|
||||
}
|
||||
}
|
||||
return B_OK;
|
||||
@ -220,21 +162,11 @@ status_t MediaWriterAddOn::SniffTypeKind(
|
||||
int32 * out_internal_id,
|
||||
void * _reserved)
|
||||
{
|
||||
fprintf(stderr,"MediaWriterAddOn::SniffTypeKind\n");
|
||||
if ((out_quality == 0) || (out_internal_id == 0)) {
|
||||
fprintf(stderr,"<- B_BAD_VALUE\n");
|
||||
return B_BAD_VALUE; // we refuse to crash because you were stupid
|
||||
}
|
||||
if (in_kinds & (B_BUFFER_CONSUMER | B_FILE_INTERFACE | B_CONTROLLABLE)) {
|
||||
return SniffType(type,out_quality,out_internal_id);
|
||||
} else {
|
||||
// They asked for some kind we don't supply. We set the output
|
||||
// just in case they try to do something with it anyway (!)
|
||||
*out_quality = 0;
|
||||
*out_internal_id = -1;
|
||||
fprintf(stderr,"<- B_BAD_TYPE\n");
|
||||
return B_BAD_TYPE;
|
||||
}
|
||||
fprintf(stderr,"MediaReaderAddOn::SniffTypeKind\n");
|
||||
return AbstractFileInterfaceAddOn::SniffTypeKind(type,in_kinds,
|
||||
B_BUFFER_CONSUMER,
|
||||
out_quality,out_internal_id,
|
||||
_reserved);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------- //
|
||||
|
@ -12,9 +12,10 @@
|
||||
|
||||
#include <MediaDefs.h>
|
||||
#include <MediaAddOn.h>
|
||||
#include "../AbstractFileInterfaceAddOn.h"
|
||||
|
||||
class MediaWriterAddOn :
|
||||
public BMediaAddOn
|
||||
public AbstractFileInterfaceAddOn
|
||||
{
|
||||
public:
|
||||
virtual ~MediaWriterAddOn(void);
|
||||
@ -23,9 +24,6 @@ public:
|
||||
/**************************/
|
||||
/* begin from BMediaAddOn */
|
||||
public:
|
||||
virtual status_t InitCheck(
|
||||
const char ** out_failure_text);
|
||||
virtual int32 CountFlavors(void);
|
||||
virtual status_t GetFlavorAt(
|
||||
int32 n,
|
||||
const flavor_info ** out_info);
|
||||
@ -36,23 +34,8 @@ virtual BMediaNode * InstantiateNodeFor(
|
||||
virtual status_t GetConfigurationFor(
|
||||
BMediaNode * your_node,
|
||||
BMessage * into_message);
|
||||
virtual bool WantsAutoStart(void);
|
||||
virtual status_t AutoStart(
|
||||
int in_count,
|
||||
BMediaNode ** out_node,
|
||||
int32 * out_internal_id,
|
||||
bool * out_has_more);
|
||||
|
||||
/* only implement if you have a B_FILE_INTERFACE node */
|
||||
virtual status_t SniffRef(
|
||||
const entry_ref & file,
|
||||
BMimeType * io_mime_type,
|
||||
float * out_quality,
|
||||
int32 * out_internal_id);
|
||||
virtual status_t SniffType( // This is broken if you deal with producers
|
||||
const BMimeType & type, // and consumers both. Use SniffTypeKind instead.
|
||||
float * out_quality, // If you implement SniffTypeKind, this doesn't
|
||||
int32 * out_internal_id); // get called.
|
||||
virtual status_t GetFileFormatList(
|
||||
int32 flavor_id, // for this node flavor (if it matters)
|
||||
media_file_format * out_writable_formats, // don't write here if NULL
|
||||
@ -69,7 +52,6 @@ virtual status_t SniffTypeKind( // Like SniffType, but for the specific kind(
|
||||
int32 * out_internal_id,
|
||||
void * _reserved);
|
||||
|
||||
|
||||
/* end from BMediaAddOn */
|
||||
/************************/
|
||||
|
||||
@ -80,8 +62,6 @@ private:
|
||||
MediaWriterAddOn & operator=(
|
||||
const MediaWriterAddOn & clone);
|
||||
|
||||
int32 refCount;
|
||||
|
||||
/* Mmmh, stuffing! */
|
||||
virtual status_t _Reserved_MediaWriterAddOn_0(void *);
|
||||
virtual status_t _Reserved_MediaWriterAddOn_1(void *);
|
||||
|
Loading…
Reference in New Issue
Block a user