Removed superflous NULL pointer checks.

The media kit will always call BMediaNode 
and BMediaAddOn functions with valid pointers.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25232 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Marcus Overhagen
2008-04-28 22:13:36 +00:00
parent 5b330b7af6
commit bcf291ed9b
12 changed files with 23 additions and 303 deletions
@@ -60,10 +60,6 @@ status_t AbstractFileInterfaceAddOn::GetFlavorAt(
{ {
CALLED(); CALLED();
if (out_info == 0) {
PRINT("\t<- B_BAD_VALUE\n");
return B_BAD_VALUE; // avoid crash
}
if (n != 0) { if (n != 0) {
PRINT("\t<- B_BAD_INDEX\n"); PRINT("\t<- B_BAD_INDEX\n");
return B_BAD_INDEX; return B_BAD_INDEX;
@@ -81,10 +77,6 @@ status_t AbstractFileInterfaceAddOn::GetConfigurationFor(
BMessage * into_message) BMessage * into_message)
{ {
CALLED(); CALLED();
if (into_message == 0) {
PRINT("\t<- B_BAD_VALUE\n");
return B_BAD_VALUE; // avoid crash
}
AbstractFileInterfaceNode * node AbstractFileInterfaceNode * node
= dynamic_cast<AbstractFileInterfaceNode*>(your_node); = dynamic_cast<AbstractFileInterfaceNode*>(your_node);
if (node == 0) { if (node == 0) {
@@ -124,11 +116,6 @@ status_t AbstractFileInterfaceAddOn::SniffRef(
{ {
CALLED(); CALLED();
if ((io_mime_type == 0) || (out_quality == 0) || (out_internal_id == 0)) {
PRINT("\t<- B_BAD_VALUE\n");
return B_BAD_VALUE; // avoid crash
}
*out_internal_id = 0; // only one flavor *out_internal_id = 0; // only one flavor
char mime_string[B_MIME_TYPE_LENGTH+1]; char mime_string[B_MIME_TYPE_LENGTH+1];
status_t status = AbstractFileInterfaceNode::StaticSniffRef(file,mime_string,out_quality); status_t status = AbstractFileInterfaceNode::StaticSniffRef(file,mime_string,out_quality);
@@ -146,23 +133,12 @@ status_t AbstractFileInterfaceAddOn::SniffType(
{ {
CALLED(); CALLED();
if ((out_quality == 0) || (out_internal_id == 0)) {
PRINT("\t<- B_BAD_VALUE\n");
return B_BAD_VALUE; // avoid crash
}
*out_quality = 1.0; *out_quality = 1.0;
*out_internal_id = 0; *out_internal_id = 0;
return B_OK; 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 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.
status_t AbstractFileInterfaceAddOn::GetFileFormatList( status_t AbstractFileInterfaceAddOn::GetFileFormatList(
int32 flavor_id, int32 flavor_id,
media_file_format * out_writable_formats, media_file_format * out_writable_formats,
@@ -180,12 +156,8 @@ status_t AbstractFileInterfaceAddOn::GetFileFormatList(
PRINT("\t<- B_BAD_INDEX\n"); PRINT("\t<- B_BAD_INDEX\n");
return B_BAD_INDEX; return B_BAD_INDEX;
} }
// see null check comment above
if (out_write_items != 0)
*out_write_items = 0;
// see null check comment above *out_write_items = 0;
if (out_read_items != 0)
*out_read_items = 0; *out_read_items = 0;
return B_OK; return B_OK;
@@ -202,10 +174,6 @@ status_t AbstractFileInterfaceAddOn::SniffTypeKind(
{ {
CALLED(); CALLED();
if ((out_quality == 0) || (out_internal_id == 0)) {
PRINT("\t<- B_BAD_VALUE\n");
return B_BAD_VALUE; // avoid crash
}
if (in_kinds & (io_kind | B_FILE_INTERFACE | B_CONTROLLABLE)) { if (in_kinds & (io_kind | B_FILE_INTERFACE | B_CONTROLLABLE)) {
return SniffType(type,out_quality,out_internal_id); return SniffType(type,out_quality,out_internal_id);
} else { } else {
@@ -304,23 +304,14 @@ status_t AbstractFileInterfaceNode::GetNextFileFormat(
{ {
CALLED(); CALLED();
// avoid crashes
if (out_format == 0) {
// no place to write!
PRINT("\t<- B_BAD_VALUE\n");
return B_BAD_VALUE;
}
if (cookie != 0) {
// it's valid but they already got our 1 file format // it's valid but they already got our 1 file format
if (*cookie != 0) { if (*cookie != 0) {
PRINT("\t<- B_ERROR\n"); PRINT("\t<- B_ERROR\n");
return B_ERROR; return B_ERROR;
} }
// so next time they won't get the same format again // so next time they won't get the same format again
*cookie = 1; *cookie = 1;
}
GetFileFormat(out_format); GetFileFormat(out_format);
return B_OK; return B_OK;
} }
@@ -370,11 +361,6 @@ status_t AbstractFileInterfaceNode::SetRef(
{ {
CALLED(); CALLED();
if (out_time == 0) {
PRINT("\t<- B_BAD_VALUE\n");
return B_BAD_VALUE; // no crashes today thanks
}
status_t status; status_t status;
f_current_ref = file; f_current_ref = file;
if (fCurrentFile == 0) { if (fCurrentFile == 0) {
@@ -402,11 +388,6 @@ status_t AbstractFileInterfaceNode::GetRef(
{ {
CALLED(); CALLED();
if ((out_ref == 0) || (out_mime_type == 0)) {
PRINT("\t<- B_BAD_VALUE\n");
return B_BAD_VALUE; // avoid crash
}
if (fCurrentFile == 0) { if (fCurrentFile == 0) {
PRINT("\t<- B_NO_INIT\n"); PRINT("\t<- B_NO_INIT\n");
return B_NO_INIT; // the input_ref isn't valid yet either return B_NO_INIT; // the input_ref isn't valid yet either
@@ -427,11 +408,6 @@ status_t AbstractFileInterfaceNode::StaticSniffRef(
{ {
CALLED(); CALLED();
if ((out_mime_type == 0) || (out_quality == 0)) {
PRINT("\t<- B_BAD_VALUE\n");
return B_BAD_VALUE; // avoid crash
}
BNode node(&file); BNode node(&file);
status_t initCheck = node.InitCheck(); status_t initCheck = node.InitCheck();
if (initCheck != B_OK) { if (initCheck != B_OK) {
@@ -462,9 +438,6 @@ status_t AbstractFileInterfaceNode::GetParameterValue(
{ {
CALLED(); CALLED();
if ((last_change == 0) || (value == 0) || (ioSize == 0))
return B_BAD_VALUE; // no crashing
switch (id) { switch (id) {
case DEFAULT_CHUNK_SIZE_PARAM: case DEFAULT_CHUNK_SIZE_PARAM:
if (*ioSize < sizeof(size_t)) { if (*ioSize < sizeof(size_t)) {
@@ -62,10 +62,6 @@ status_t MediaDemultiplexerAddOn::GetFlavorAt(
const flavor_info ** out_info) const flavor_info ** out_info)
{ {
fprintf(stderr,"MediaDemultiplexerAddOn::GetFlavorAt\n"); fprintf(stderr,"MediaDemultiplexerAddOn::GetFlavorAt\n");
if (out_info == 0) {
fprintf(stderr,"<- B_BAD_VALUE\n");
return B_BAD_VALUE; // we refuse to crash because you were stupid
}
if (n != 0) { if (n != 0) {
fprintf(stderr,"<- B_BAD_INDEX\n"); fprintf(stderr,"<- B_BAD_INDEX\n");
return B_BAD_INDEX; return B_BAD_INDEX;
@@ -82,10 +78,6 @@ BMediaNode * MediaDemultiplexerAddOn::InstantiateNodeFor(
status_t * out_error) status_t * out_error)
{ {
fprintf(stderr,"MediaDemultiplexerAddOn::InstantiateNodeFor\n"); fprintf(stderr,"MediaDemultiplexerAddOn::InstantiateNodeFor\n");
if (out_error == 0) {
fprintf(stderr,"<- NULL\n");
return 0; // we refuse to crash because you were stupid
}
MediaDemultiplexerNode * node MediaDemultiplexerNode * node
= new MediaDemultiplexerNode(info,config,this); = new MediaDemultiplexerNode(info,config,this);
if (node == 0) { if (node == 0) {
@@ -102,10 +94,6 @@ status_t MediaDemultiplexerAddOn::GetConfigurationFor(
BMessage * into_message) BMessage * into_message)
{ {
fprintf(stderr,"MediaDemultiplexerAddOn::GetConfigurationFor\n"); fprintf(stderr,"MediaDemultiplexerAddOn::GetConfigurationFor\n");
if (into_message == 0) {
fprintf(stderr,"<- B_BAD_VALUE\n");
return B_BAD_VALUE; // we refuse to crash because you were stupid
}
MediaDemultiplexerNode * node MediaDemultiplexerNode * node
= dynamic_cast<MediaDemultiplexerNode*>(your_node); = dynamic_cast<MediaDemultiplexerNode*>(your_node);
if (node == 0) { if (node == 0) {
@@ -243,10 +243,6 @@ status_t MediaDemultiplexerNode::AcceptFormat(
media_format * format) media_format * format)
{ {
fprintf(stderr,"MediaDemultiplexerNode::AcceptFormat\n"); fprintf(stderr,"MediaDemultiplexerNode::AcceptFormat\n");
if (format == 0) {
fprintf(stderr,"<- B_BAD_VALUE\n");
return B_BAD_VALUE; // no crashing
}
if (input.destination != dest) { if (input.destination != dest) {
fprintf(stderr,"<- B_MEDIA_BAD_DESTINATION"); fprintf(stderr,"<- B_MEDIA_BAD_DESTINATION");
return B_MEDIA_BAD_DESTINATION; // we only have one input so that better be it return B_MEDIA_BAD_DESTINATION; // we only have one input so that better be it
@@ -268,21 +264,13 @@ status_t MediaDemultiplexerNode::GetNextInput(
media_input * out_input) media_input * out_input)
{ {
fprintf(stderr,"MediaDemultiplexerNode::GetNextInput\n"); fprintf(stderr,"MediaDemultiplexerNode::GetNextInput\n");
// let's not crash even if they are stupid
if (out_input == 0) {
// no place to write!
fprintf(stderr,"<- B_BAD_VALUE\n");
return B_BAD_VALUE;
}
if (cookie != 0) {
// it's valid but they already got our 1 input
if (*cookie != 0) { if (*cookie != 0) {
fprintf(stderr,"<- B_ERROR (no more inputs)\n"); fprintf(stderr,"<- B_ERROR (no more inputs)\n");
return B_ERROR; return B_ERROR;
} }
// so next time they won't get the same input again // so next time they won't get the same input again
*cookie = 1; *cookie = 1;
}
*out_input = input; *out_input = input;
return B_OK; return B_OK;
} }
@@ -372,10 +360,6 @@ status_t MediaDemultiplexerNode::Connected(
media_input * out_input) media_input * out_input)
{ {
fprintf(stderr,"MediaDemultiplexerNode::Connected\n"); fprintf(stderr,"MediaDemultiplexerNode::Connected\n");
if (out_input == 0) {
fprintf(stderr,"<- B_BAD_VALUE\n");
return B_BAD_VALUE; // no crashing
}
if (input.destination != where) { if (input.destination != where) {
fprintf(stderr,"<- B_MEDIA_BAD_DESTINATION\n"); fprintf(stderr,"<- B_MEDIA_BAD_DESTINATION\n");
return B_MEDIA_BAD_DESTINATION; return B_MEDIA_BAD_DESTINATION;
@@ -473,10 +457,6 @@ status_t MediaDemultiplexerNode::FormatSuggestionRequested(
media_format * format) media_format * format)
{ {
fprintf(stderr,"MediaDemultiplexerNode::FormatSuggestionRequested\n"); fprintf(stderr,"MediaDemultiplexerNode::FormatSuggestionRequested\n");
if (format == 0) {
fprintf(stderr,"<- B_BAD_VALUE\n");
return B_BAD_VALUE; // no crashing
}
// XXX: how do I pick which stream to supply here?.... // XXX: how do I pick which stream to supply here?....
// answer?: get the first compatible stream that is available // answer?: get the first compatible stream that is available
fprintf(stderr," format suggestion requested not implemented\n"); fprintf(stderr," format suggestion requested not implemented\n");
@@ -544,12 +524,6 @@ status_t MediaDemultiplexerNode::GetNextOutput( /* cookie starts as 0 */
media_output * out_output) media_output * out_output)
{ {
fprintf(stderr,"MediaDemultiplexerNode::GetNextOutput\n"); fprintf(stderr,"MediaDemultiplexerNode::GetNextOutput\n");
// let's not crash even if they are stupid
if ((out_output == 0) || (cookie == 0)) {
// no place to write!
fprintf(stderr,"<- B_BAD_VALUE\n");
return B_BAD_VALUE;
}
// they want a clean start // they want a clean start
if (*cookie == 0) { if (*cookie == 0) {
*cookie = (int32)outputs.begin(); *cookie = (int32)outputs.begin();
@@ -637,10 +611,6 @@ status_t MediaDemultiplexerNode::PrepareToConnect(
char * out_name) char * out_name)
{ {
fprintf(stderr,"MediaDemultiplexerNode::PrepareToConnect\n"); fprintf(stderr,"MediaDemultiplexerNode::PrepareToConnect\n");
if ((format == 0) || (out_source == 0) || (out_name == 0)) {
fprintf(stderr,"<- B_BAD_VALUE\n");
return B_BAD_VALUE; // no crashes...
}
// find the information for this output // find the information for this output
vector<MediaOutputInfo>::iterator itr; vector<MediaOutputInfo>::iterator itr;
for(itr = outputs.begin() ; (itr != outputs.end()) ; itr++) { for(itr = outputs.begin() ; (itr != outputs.end()) ; itr++) {
@@ -53,10 +53,6 @@ status_t MediaOutputInfo::SetBufferGroup(BBufferGroup * group) {
// that. We leave wildcards for anything that we don't care about. // that. We leave wildcards for anything that we don't care about.
status_t MediaOutputInfo::FormatProposal(media_format * format) status_t MediaOutputInfo::FormatProposal(media_format * format)
{ {
if (format == 0) {
fprintf(stderr,"<- B_BAD_VALUE\n");
return B_BAD_VALUE; // no crashing
}
// Be's format_is_compatible doesn't work, // Be's format_is_compatible doesn't work,
// so use our format_is_acceptible instead // so use our format_is_acceptible instead
if (!format_is_acceptible(*format,generalFormat)) { if (!format_is_acceptible(*format,generalFormat)) {
@@ -75,10 +71,6 @@ status_t MediaOutputInfo::FormatProposal(media_format * format)
status_t MediaOutputInfo::FormatChangeRequested(const media_destination & destination, status_t MediaOutputInfo::FormatChangeRequested(const media_destination & destination,
media_format * io_format) media_format * io_format)
{ {
if (io_format == 0) {
fprintf(stderr,"<- B_BAD_VALUE\n");
return B_BAD_VALUE; // no crashing
}
status_t status = FormatProposal(io_format); status_t status = FormatProposal(io_format);
if (status != B_OK) { if (status != B_OK) {
fprintf(stderr,"<- MediaOutputInfo::FormatProposal failed\n"); fprintf(stderr,"<- MediaOutputInfo::FormatProposal failed\n");
@@ -115,10 +107,6 @@ status_t MediaOutputInfo::Connect(const media_destination & destination,
char * io_name, char * io_name,
bigtime_t _downstreamLatency) bigtime_t _downstreamLatency)
{ {
if (io_name == 0) {
fprintf(stderr,"<- B_BAD_VALUE\n");
return B_BAD_VALUE;
}
output.destination = destination; output.destination = destination;
output.format = format; output.format = format;
strncpy(io_name,output.name,B_MEDIA_NAME_LENGTH-1); strncpy(io_name,output.name,B_MEDIA_NAME_LENGTH-1);
@@ -113,10 +113,6 @@ status_t ESDSinkAddOn::GetFlavorAt(
const flavor_info ** out_info) const flavor_info ** out_info)
{ {
CALLED(); CALLED();
if (out_info == 0) {
fprintf(stderr,"<- B_BAD_VALUE\n");
return B_BAD_VALUE; // we refuse to crash because you were stupid
}
//if (n < 0 || n > fDevices.CountItems() - 1) { //if (n < 0 || n > fDevices.CountItems() - 1) {
if (n < 0 || n > 1) { if (n < 0 || n > 1) {
fprintf(stderr,"<- B_BAD_INDEX\n"); fprintf(stderr,"<- B_BAD_INDEX\n");
@@ -139,14 +135,6 @@ BMediaNode * ESDSinkAddOn::InstantiateNodeFor(
status_t * out_error) status_t * out_error)
{ {
CALLED(); CALLED();
if (out_error == 0) {
fprintf(stderr,"<- NULL\n");
return 0; // we refuse to crash because you were stupid
}
BMessage defaults;
if (!config)
config = &defaults;
#ifdef MULTI_SAVE #ifdef MULTI_SAVE
if(fSettings.FindMessage(device->MD.friendly_name, config)==B_OK) { if(fSettings.FindMessage(device->MD.friendly_name, config)==B_OK) {
@@ -173,7 +161,6 @@ ESDSinkAddOn::GetConfigurationFor(BMediaNode * your_node, BMessage * into_messag
{ {
CALLED(); CALLED();
#ifdef MULTI_SAVE #ifdef MULTI_SAVE
if (into_message == 0) {
into_message = new BMessage(); into_message = new BMessage();
ESDSinkNode * node = dynamic_cast<ESDSinkNode*>(your_node); ESDSinkNode * node = dynamic_cast<ESDSinkNode*>(your_node);
if (node == 0) { if (node == 0) {
@@ -184,13 +171,9 @@ ESDSinkAddOn::GetConfigurationFor(BMediaNode * your_node, BMessage * into_messag
fSettings.AddMessage(your_node->Name(), into_message); fSettings.AddMessage(your_node->Name(), into_message);
} }
return B_OK; return B_OK;
}
#endif #endif
// currently never called by the media kit. Seems it is not implemented. // currently never called by the media kit. Seems it is not implemented.
if (into_message == 0) {
fprintf(stderr,"<- B_BAD_VALUE\n");
return B_BAD_VALUE; // we refuse to crash because you were stupid
}
ESDSinkNode * node = dynamic_cast<ESDSinkNode*>(your_node); ESDSinkNode * node = dynamic_cast<ESDSinkNode*>(your_node);
if (node == 0) { if (node == 0) {
fprintf(stderr,"<- B_BAD_TYPE\n"); fprintf(stderr,"<- B_BAD_TYPE\n");
@@ -267,10 +267,6 @@ status_t ESDSinkNode::AcceptFormat(
return B_MEDIA_BAD_DESTINATION; // we only have one input so that better be it return B_MEDIA_BAD_DESTINATION; // we only have one input so that better be it
} }
if (format == 0) {
fprintf(stderr,"<- B_BAD_VALUE\n");
return B_BAD_VALUE; // no crashing
}
/* media_format * myFormat = GetFormat(); /* media_format * myFormat = GetFormat();
fprintf(stderr,"proposed format: "); fprintf(stderr,"proposed format: ");
print_media_format(format); print_media_format(format);
@@ -316,12 +312,6 @@ status_t ESDSinkNode::GetNextInput(
media_input * out_input) media_input * out_input)
{ {
CALLED(); CALLED();
// let's not crash even if they are stupid
if (out_input == 0) {
// no place to write!
fprintf(stderr,"<- B_BAD_VALUE\n");
return B_BAD_VALUE;
}
if ((*cookie < 1) && (*cookie >= 0)) { if ((*cookie < 1) && (*cookie >= 0)) {
*out_input = fInput; *out_input = fInput;
@@ -436,10 +426,6 @@ status_t ESDSinkNode::Connected(
media_input * out_input) media_input * out_input)
{ {
CALLED(); CALLED();
if (out_input == 0) {
fprintf(stderr,"<- B_BAD_VALUE\n");
return B_BAD_VALUE; // no crashing
}
if(fInput.destination != where) { if(fInput.destination != where) {
fprintf(stderr,"<- B_MEDIA_BAD_DESTINATION\n"); fprintf(stderr,"<- B_MEDIA_BAD_DESTINATION\n");
@@ -1401,9 +1387,6 @@ ESDSinkNode::GetConfigurationFor(BMessage * into_message)
bigtime_t last_change; bigtime_t last_change;
status_t err; status_t err;
if(!into_message)
return B_BAD_VALUE;
buffer = malloc(size); buffer = malloc(size);
for(int32 i=0; i<fWeb->CountParameters(); i++) { for(int32 i=0; i<fWeb->CountParameters(); i++) {
@@ -1438,9 +1421,6 @@ ESDSinkNode::GetConfigurationFor(BMessage * into_message)
void ESDSinkNode::GetFlavor(flavor_info * outInfo, int32 id) void ESDSinkNode::GetFlavor(flavor_info * outInfo, int32 id)
{ {
CALLED(); CALLED();
if (outInfo == 0) {
return;
}
outInfo->flavor_flags = B_FLAVOR_IS_GLOBAL; outInfo->flavor_flags = B_FLAVOR_IS_GLOBAL;
// outInfo->possible_count = 0; // any number // outInfo->possible_count = 0; // any number
@@ -1475,9 +1455,7 @@ void ESDSinkNode::GetFlavor(flavor_info * outInfo, int32 id)
void ESDSinkNode::GetFormat(media_format * outFormat) void ESDSinkNode::GetFormat(media_format * outFormat)
{ {
CALLED(); CALLED();
if (outFormat == 0) {
return;
}
outFormat->type = B_MEDIA_RAW_AUDIO; outFormat->type = B_MEDIA_RAW_AUDIO;
outFormat->require_flags = B_MEDIA_MAUI_UNDEFINED_FLAGS; outFormat->require_flags = B_MEDIA_MAUI_UNDEFINED_FLAGS;
outFormat->deny_flags = B_MEDIA_MAUI_UNDEFINED_FLAGS; outFormat->deny_flags = B_MEDIA_MAUI_UNDEFINED_FLAGS;
@@ -84,8 +84,6 @@ status_t
MultiAudioAddOn::GetFlavorAt(int32 index, const flavor_info** _info) MultiAudioAddOn::GetFlavorAt(int32 index, const flavor_info** _info)
{ {
CALLED(); CALLED();
if (_info == NULL)
return B_BAD_VALUE;
MultiAudioDevice* device = (MultiAudioDevice*)fDevices.ItemAt(index); MultiAudioDevice* device = (MultiAudioDevice*)fDevices.ItemAt(index);
if (device == NULL) if (device == NULL)
@@ -108,8 +106,6 @@ MultiAudioAddOn::InstantiateNodeFor(const flavor_info* info, BMessage* config,
status_t* _error) status_t* _error)
{ {
CALLED(); CALLED();
if (_error == NULL)
return NULL;
MultiAudioDevice* device = (MultiAudioDevice*)fDevices.ItemAt( MultiAudioDevice* device = (MultiAudioDevice*)fDevices.ItemAt(
info->internal_id); info->internal_id);
@@ -155,8 +151,6 @@ MultiAudioAddOn::GetConfigurationFor(BMediaNode* _node, BMessage* message)
#endif #endif
// currently never called by the media kit. Seems it is not implemented. // currently never called by the media kit. Seems it is not implemented.
if (message == NULL)
return B_BAD_VALUE;
return node->GetConfigurationFor(message); return node->GetConfigurationFor(message);
} }
@@ -98,10 +98,6 @@ status_t OpenSoundAddOn::GetFlavorAt(
const flavor_info ** out_info) const flavor_info ** out_info)
{ {
CALLED(); CALLED();
if (out_info == 0) {
fprintf(stderr, "<- B_BAD_VALUE\n");
return B_BAD_VALUE; // we refuse to crash because you were stupid
}
if (n < 0 || n > fDevices.CountItems() - 1) { if (n < 0 || n > fDevices.CountItems() - 1) {
fprintf(stderr, "<- B_BAD_INDEX\n"); fprintf(stderr, "<- B_BAD_INDEX\n");
return B_BAD_INDEX; return B_BAD_INDEX;
@@ -122,16 +118,6 @@ BMediaNode * OpenSoundAddOn::InstantiateNodeFor(
status_t * out_error) status_t * out_error)
{ {
CALLED(); CALLED();
if (out_error == 0) {
fprintf(stderr, "<- NULL\n");
return 0; // we refuse to crash because you were stupid
}
BMessage fakeConfig;
if (config == 0) {
fprintf(stderr, "<- config == NULL\n");
config = &fakeConfig; // we refuse to crash because you were stupid
}
OpenSoundDevice *device = (OpenSoundDevice*)fDevices.ItemAt(info->internal_id); OpenSoundDevice *device = (OpenSoundDevice*)fDevices.ItemAt(info->internal_id);
if (device == NULL) { if (device == NULL) {
@@ -165,7 +151,7 @@ OpenSoundAddOn::GetConfigurationFor(BMediaNode * your_node, BMessage * into_mess
{ {
CALLED(); CALLED();
#ifdef MULTI_SAVE #ifdef MULTI_SAVE
if (into_message == 0) { {
into_message = new BMessage(); into_message = new BMessage();
OpenSoundNode * node = dynamic_cast<OpenSoundNode*>(your_node); OpenSoundNode * node = dynamic_cast<OpenSoundNode*>(your_node);
if (node == 0) { if (node == 0) {
@@ -179,10 +165,6 @@ OpenSoundAddOn::GetConfigurationFor(BMediaNode * your_node, BMessage * into_mess
} }
#endif #endif
// currently never called by the media kit. Seems it is not implemented. // currently never called by the media kit. Seems it is not implemented.
if (into_message == 0) {
fprintf(stderr, "<- B_BAD_VALUE\n");
return B_BAD_VALUE; // we refuse to crash because you were stupid
}
OpenSoundNode * node = dynamic_cast<OpenSoundNode*>(your_node); OpenSoundNode * node = dynamic_cast<OpenSoundNode*>(your_node);
if (node == 0) { if (node == 0) {
fprintf(stderr, "<- B_BAD_TYPE\n"); fprintf(stderr, "<- B_BAD_TYPE\n");
@@ -221,11 +221,6 @@ status_t MediaReader::FormatSuggestionRequested(
{ {
CALLED(); CALLED();
if (format == 0) {
PRINT("\t<- B_BAD_VALUE\n");
return B_BAD_VALUE; // no crashing
}
if ((type != B_MEDIA_MULTISTREAM) && (type != B_MEDIA_UNKNOWN_TYPE)) { if ((type != B_MEDIA_MULTISTREAM) && (type != B_MEDIA_UNKNOWN_TYPE)) {
PRINT("\t<- B_MEDIA_BAD_FORMAT\n"); PRINT("\t<- B_MEDIA_BAD_FORMAT\n");
return B_MEDIA_BAD_FORMAT; return B_MEDIA_BAD_FORMAT;
@@ -246,10 +241,6 @@ status_t MediaReader::FormatProposal(
{ {
CALLED(); CALLED();
if (format == 0) {
PRINT("\t<- B_BAD_VALUE\n");
return B_BAD_VALUE; // no crashing
}
if (output.source != output_source) { if (output.source != output_source) {
PRINT("\t<- B_MEDIA_BAD_SOURCE\n"); PRINT("\t<- B_MEDIA_BAD_SOURCE\n");
return B_MEDIA_BAD_SOURCE; // we only have one output so that better be it return B_MEDIA_BAD_SOURCE; // we only have one output so that better be it
@@ -286,10 +277,6 @@ status_t MediaReader::FormatChangeRequested(
{ {
CALLED(); CALLED();
if (io_format == 0) {
PRINT("\t<- B_BAD_VALUE\n");
return B_BAD_VALUE; // no crashing
}
if (output.source != source) { if (output.source != source) {
PRINT("\t<- B_MEDIA_BAD_SOURCE\n"); PRINT("\t<- B_MEDIA_BAD_SOURCE\n");
return B_MEDIA_BAD_SOURCE; return B_MEDIA_BAD_SOURCE;
@@ -311,21 +298,13 @@ status_t MediaReader::GetNextOutput( /* cookie starts as 0 */
{ {
CALLED(); CALLED();
// let's not crash even if they are stupid
if (out_output == 0) {
// no place to write!
PRINT("\t<- B_BAD_VALUE\n");
return B_BAD_VALUE;
}
if (cookie != 0) {
// it's valid but they already got our 1 output
if (*cookie != 0) { if (*cookie != 0) {
PRINT("\t<- B_ERROR (no more outputs)\n"); PRINT("\t<- B_ERROR (no more outputs)\n");
return B_ERROR; return B_ERROR;
} }
// so next time they won't get the same output again // so next time they won't get the same output again
*cookie = 1; *cookie = 1;
}
*out_output = output; *out_output = output;
return B_OK; return B_OK;
} }
@@ -417,10 +396,6 @@ status_t MediaReader::GetLatency(
{ {
CALLED(); CALLED();
if (out_latency == 0) {
PRINT("\t<- B_BAD_VALUE\n");
return B_BAD_VALUE;
}
*out_latency = EventLatency() + SchedulingLatency(); *out_latency = EventLatency() + SchedulingLatency();
return B_OK; return B_OK;
} }
@@ -435,11 +410,6 @@ status_t MediaReader::PrepareToConnect(
{ {
CALLED(); CALLED();
if ((format == 0) || (out_source == 0) || (out_name == 0)) {
PRINT("\ŧ<- B_BAD_VALUE\n");
return B_BAD_VALUE; // no crashes...
}
if (output.source != what) { if (output.source != what) {
PRINT("\t<- B_MEDIA_BAD_SOURCE\n"); PRINT("\t<- B_MEDIA_BAD_SOURCE\n");
return B_MEDIA_BAD_SOURCE; return B_MEDIA_BAD_SOURCE;
@@ -773,9 +743,6 @@ void MediaReader::GetFormat(media_format * outFormat)
{ {
CALLED(); CALLED();
if (outFormat == 0)
return;
AbstractFileInterfaceNode::GetFormat(outFormat); AbstractFileInterfaceNode::GetFormat(outFormat);
return; return;
} }
@@ -785,9 +752,6 @@ void MediaReader::GetFileFormat(media_file_format * outFileFormat)
{ {
CALLED(); CALLED();
if (outFileFormat == 0)
return;
AbstractFileInterfaceNode::GetFileFormat(outFileFormat); AbstractFileInterfaceNode::GetFileFormat(outFileFormat);
outFileFormat->capabilities |= media_file_format::B_READABLE; outFileFormat->capabilities |= media_file_format::B_READABLE;
return; return;
@@ -51,10 +51,6 @@ status_t MediaReaderAddOn::GetFlavorAt(
{ {
CALLED(); CALLED();
if (out_info == 0) {
PRINT("\t<- B_BAD_VALUE\n");
return B_BAD_VALUE; // avoid crash
}
if (n != 0) { if (n != 0) {
PRINT("\t<- B_BAD_INDEX\n"); PRINT("\t<- B_BAD_INDEX\n");
return B_BAD_INDEX; return B_BAD_INDEX;
@@ -74,11 +70,6 @@ BMediaNode * MediaReaderAddOn::InstantiateNodeFor(
{ {
CALLED(); CALLED();
if (out_error == 0) {
PRINT("\t<- NULL\n");
return 0; // avoid crash
}
// XXX: read from add-on's attributes // XXX: read from add-on's attributes
size_t defaultChunkSize = size_t(8192); // 8192 bytes = 8 Kilobytes size_t defaultChunkSize = size_t(8192); // 8192 bytes = 8 Kilobytes
// = 2048 kilobits/millisec = 256000 Kilobytes/sec // = 2048 kilobits/millisec = 256000 Kilobytes/sec
@@ -103,11 +94,6 @@ status_t MediaReaderAddOn::GetConfigurationFor(
{ {
CALLED(); CALLED();
if (into_message == 0) {
PRINT("\t<- B_BAD_VALUE\n");
return B_BAD_VALUE; // avoid crash
}
MediaReader * node MediaReader * node
= dynamic_cast<MediaReader*>(your_node); = dynamic_cast<MediaReader*>(your_node);
if (node == 0) { if (node == 0) {
@@ -122,17 +108,6 @@ status_t MediaReaderAddOn::GetConfigurationFor(
// BMediaAddOn impl for B_FILE_INTERFACE nodes // BMediaAddOn impl for B_FILE_INTERFACE nodes
// -------------------------------------------------------- // // -------------------------------------------------------- //
// 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 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...
status_t MediaReaderAddOn::GetFileFormatList( status_t MediaReaderAddOn::GetFileFormatList(
int32 flavor_id, int32 flavor_id,
media_file_format * out_writable_formats, media_file_format * out_writable_formats,
@@ -150,20 +125,10 @@ status_t MediaReaderAddOn::GetFileFormatList(
PRINT("\t<- B_BAD_INDEX\n"); PRINT("\t<- B_BAD_INDEX\n");
return B_BAD_INDEX; return B_BAD_INDEX;
} }
// see null check comment above
if (out_write_items != 0) {
*out_write_items = 0;
}
// see null check comment above
if (out_read_items != 0) {
*out_read_items = 1;
}
if (out_readable_formats != 0) {
// don't go off the end // don't go off the end
if (in_read_items > 0) { if (in_read_items > 0) {
MediaReader::GetFileFormat(&out_readable_formats[0]); MediaReader::GetFileFormat(&out_readable_formats[0]);
} }
}
return B_OK; return B_OK;
} }
@@ -50,10 +50,6 @@ status_t MediaWriterAddOn::GetFlavorAt(
const flavor_info ** out_info) const flavor_info ** out_info)
{ {
fprintf(stderr,"MediaWriterAddOn::GetFlavorAt\n"); fprintf(stderr,"MediaWriterAddOn::GetFlavorAt\n");
if (out_info == 0) {
fprintf(stderr,"<- B_BAD_VALUE\n");
return B_BAD_VALUE; // we refuse to crash because you were stupid
}
if (n != 0) { if (n != 0) {
fprintf(stderr,"<- B_BAD_INDEX\n"); fprintf(stderr,"<- B_BAD_INDEX\n");
return B_BAD_INDEX; return B_BAD_INDEX;
@@ -70,10 +66,6 @@ BMediaNode * MediaWriterAddOn::InstantiateNodeFor(
status_t * out_error) status_t * out_error)
{ {
fprintf(stderr,"MediaWriterAddOn::InstantiateNodeFor\n"); fprintf(stderr,"MediaWriterAddOn::InstantiateNodeFor\n");
if (out_error == 0) {
fprintf(stderr,"<- NULL\n");
return 0; // we refuse to crash because you were stupid
}
size_t defaultChunkSize = size_t(8192); // XXX: read from add-on's attributes size_t defaultChunkSize = size_t(8192); // XXX: read from add-on's attributes
float defaultBitRate = 800000; float defaultBitRate = 800000;
MediaWriter * node MediaWriter * node
@@ -94,10 +86,6 @@ status_t MediaWriterAddOn::GetConfigurationFor(
BMessage * into_message) BMessage * into_message)
{ {
fprintf(stderr,"MediaWriterAddOn::GetConfigurationFor\n"); fprintf(stderr,"MediaWriterAddOn::GetConfigurationFor\n");
if (into_message == 0) {
fprintf(stderr,"<- B_BAD_VALUE\n");
return B_BAD_VALUE; // we refuse to crash because you were stupid
}
MediaWriter * node MediaWriter * node
= dynamic_cast<MediaWriter*>(your_node); = dynamic_cast<MediaWriter*>(your_node);
if (node == 0) { if (node == 0) {
@@ -111,17 +99,6 @@ status_t MediaWriterAddOn::GetConfigurationFor(
// BMediaAddOn impl for B_FILE_INTERFACE nodes // BMediaAddOn impl for B_FILE_INTERFACE nodes
// -------------------------------------------------------- // // -------------------------------------------------------- //
// 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 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...
status_t MediaWriterAddOn::GetFileFormatList( status_t MediaWriterAddOn::GetFileFormatList(
int32 flavor_id, int32 flavor_id,
media_file_format * out_writable_formats, media_file_format * out_writable_formats,
@@ -138,20 +115,10 @@ status_t MediaWriterAddOn::GetFileFormatList(
fprintf(stderr,"<- B_BAD_INDEX\n"); fprintf(stderr,"<- B_BAD_INDEX\n");
return B_BAD_INDEX; return B_BAD_INDEX;
} }
// see null check comment above
if (out_write_items != 0) {
*out_write_items = 0;
}
// see null check comment above
if (out_read_items != 0) {
*out_read_items = 1;
}
if (out_writable_formats != 0) {
// don't go off the end // don't go off the end
if (in_write_items > 0) { if (in_write_items > 0) {
MediaWriter::GetFileFormat(&out_writable_formats[0]); MediaWriter::GetFileFormat(&out_writable_formats[0]);
} }
}
return B_OK; return B_OK;
} }