broke out util-style functions into separate misc files.
also corrected some comments. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1142 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -7,6 +7,7 @@ Addon reader.media_addon : media :
|
|||||||
../AbstractFileInterfaceAddOn.cpp
|
../AbstractFileInterfaceAddOn.cpp
|
||||||
MediaReader.cpp
|
MediaReader.cpp
|
||||||
MediaReaderAddOn.cpp
|
MediaReaderAddOn.cpp
|
||||||
|
misc.cpp
|
||||||
;
|
;
|
||||||
|
|
||||||
LinkSharedOSLibs reader.media_addon : be media ;
|
LinkSharedOSLibs reader.media_addon : be media ;
|
||||||
|
|||||||
@@ -28,131 +28,11 @@
|
|||||||
|
|
||||||
#include "../AbstractFileInterfaceNode.h"
|
#include "../AbstractFileInterfaceNode.h"
|
||||||
#include "MediaReader.h"
|
#include "MediaReader.h"
|
||||||
|
#include "misc.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
// -------------------------------------------------------- //
|
|
||||||
// lib functions
|
|
||||||
// -------------------------------------------------------- //
|
|
||||||
|
|
||||||
/*
|
|
||||||
void print_multistream_format(media_multistream_format * format) {
|
|
||||||
fprintf(stderr,"[");
|
|
||||||
switch (format->format) {
|
|
||||||
case media_multistream_format::B_ANY: fprintf(stderr,"ANY"); break;
|
|
||||||
case media_multistream_format::B_VID: fprintf(stderr,"VID"); break;
|
|
||||||
case media_multistream_format::B_AVI: fprintf(stderr,"AVI"); break;
|
|
||||||
case media_multistream_format::B_MPEG1: fprintf(stderr,"MPEG1"); break;
|
|
||||||
case media_multistream_format::B_MPEG2: fprintf(stderr,"MPEG2"); break;
|
|
||||||
case media_multistream_format::B_QUICKTIME: fprintf(stderr,"QUICKTIME"); break;
|
|
||||||
default: fprintf(stderr,"????"); break;
|
|
||||||
}
|
|
||||||
fprintf(stderr," avg_bit_rate(%f) max_bit_rate(%f)",
|
|
||||||
format->avg_bit_rate,format->max_bit_rate);
|
|
||||||
fprintf(stderr," avg_chunk_size(%i) max_chunk_size(%i)",
|
|
||||||
format->avg_chunk_size,format->max_chunk_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void print_media_format(media_format * format) {
|
|
||||||
fprintf(stderr,"{");
|
|
||||||
switch (format->type) {
|
|
||||||
case B_MEDIA_NO_TYPE: fprintf(stderr,"NO_TYPE"); break;
|
|
||||||
case B_MEDIA_UNKNOWN_TYPE: fprintf(stderr,"UNKNOWN_TYPE"); break;
|
|
||||||
case B_MEDIA_RAW_AUDIO: fprintf(stderr,"RAW_AUDIO"); break;
|
|
||||||
case B_MEDIA_RAW_VIDEO: fprintf(stderr,"RAW_VIDEO"); break;
|
|
||||||
case B_MEDIA_VBL: fprintf(stderr,"VBL"); break;
|
|
||||||
case B_MEDIA_TIMECODE: fprintf(stderr,"TIMECODE"); break;
|
|
||||||
case B_MEDIA_MIDI: fprintf(stderr,"MIDI"); break;
|
|
||||||
case B_MEDIA_TEXT: fprintf(stderr,"TEXT"); break;
|
|
||||||
case B_MEDIA_HTML: fprintf(stderr,"HTML"); break;
|
|
||||||
case B_MEDIA_MULTISTREAM: fprintf(stderr,"MULTISTREAM"); break;
|
|
||||||
case B_MEDIA_PARAMETERS: fprintf(stderr,"PARAMETERS"); break;
|
|
||||||
case B_MEDIA_ENCODED_AUDIO: fprintf(stderr,"ENCODED_AUDIO"); break;
|
|
||||||
case B_MEDIA_ENCODED_VIDEO: fprintf(stderr,"ENCODED_VIDEO"); break;
|
|
||||||
default: fprintf(stderr,"????"); break;
|
|
||||||
}
|
|
||||||
fprintf(stderr,":");
|
|
||||||
switch (format->type) {
|
|
||||||
case B_MEDIA_RAW_AUDIO: fprintf(stderr,"RAW_AUDIO"); break;
|
|
||||||
case B_MEDIA_RAW_VIDEO: fprintf(stderr,"RAW_VIDEO"); break;
|
|
||||||
case B_MEDIA_MULTISTREAM: print_multistream_format(&format->u.multistream); break;
|
|
||||||
case B_MEDIA_ENCODED_AUDIO: fprintf(stderr,"ENCODED_AUDIO"); break;
|
|
||||||
case B_MEDIA_ENCODED_VIDEO: fprintf(stderr,"ENCODED_VIDEO"); break;
|
|
||||||
default: fprintf(stderr,"????"); break;
|
|
||||||
}
|
|
||||||
fprintf(stderr,"}");
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
bool multistream_format_is_acceptible(
|
|
||||||
const media_multistream_format & producer_format,
|
|
||||||
const media_multistream_format & consumer_format)
|
|
||||||
{
|
|
||||||
// first check the format, if necessary
|
|
||||||
if (consumer_format.format != media_multistream_format::B_ANY) {
|
|
||||||
if (consumer_format.format != producer_format.format) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// then check the average bit rate
|
|
||||||
if (consumer_format.avg_bit_rate != media_multistream_format::wildcard.avg_bit_rate) {
|
|
||||||
if (consumer_format.avg_bit_rate != producer_format.avg_bit_rate) {
|
|
||||||
// do they have to match exactly? I don't know. assume yes.
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// then check the maximum bit rate
|
|
||||||
if (consumer_format.max_bit_rate != media_multistream_format::wildcard.max_bit_rate) {
|
|
||||||
if (consumer_format.max_bit_rate != producer_format.max_bit_rate) {
|
|
||||||
// do they have to match exactly? I don't know. assume yes.
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// then check the average chunk size
|
|
||||||
if (consumer_format.avg_chunk_size != media_multistream_format::wildcard.avg_chunk_size) {
|
|
||||||
if (consumer_format.avg_chunk_size != producer_format.avg_chunk_size) {
|
|
||||||
// do they have to match exactly? I don't know. assume yes.
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// then check the maximum bit rate
|
|
||||||
if (consumer_format.max_chunk_size != media_multistream_format::wildcard.max_chunk_size) {
|
|
||||||
if (consumer_format.max_chunk_size != producer_format.max_chunk_size) {
|
|
||||||
// do they have to match exactly? I don't know. assume yes.
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// should also check format specific fields, and others?
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool format_is_acceptible(
|
|
||||||
const media_format & producer_format,
|
|
||||||
const media_format & consumer_format)
|
|
||||||
{
|
|
||||||
// first check the type, if necessary
|
|
||||||
if (consumer_format.type != B_MEDIA_UNKNOWN_TYPE) {
|
|
||||||
if (consumer_format.type != producer_format.type) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
switch (consumer_format.type) {
|
|
||||||
case B_MEDIA_MULTISTREAM:
|
|
||||||
if (!multistream_format_is_acceptible(producer_format.u.multistream,
|
|
||||||
consumer_format.u.multistream)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
fprintf(stderr,"format_is_acceptible : unimplemented type.\n");
|
|
||||||
return format_is_compatible(producer_format,consumer_format);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// should also check non-type fields?
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------------------- //
|
// -------------------------------------------------------- //
|
||||||
// ctor/dtor
|
// ctor/dtor
|
||||||
// -------------------------------------------------------- //
|
// -------------------------------------------------------- //
|
||||||
@@ -329,7 +209,7 @@ status_t MediaReader::FormatSuggestionRequested(
|
|||||||
int32 quality,
|
int32 quality,
|
||||||
media_format * format)
|
media_format * format)
|
||||||
{
|
{
|
||||||
fprintf(stderr,"MediaReader::GetRef\n");
|
fprintf(stderr,"MediaReader::FormatSuggestionRequested\n");
|
||||||
if (format == 0) {
|
if (format == 0) {
|
||||||
fprintf(stderr,"<- B_BAD_VALUE\n");
|
fprintf(stderr,"<- B_BAD_VALUE\n");
|
||||||
return B_BAD_VALUE; // no crashing
|
return B_BAD_VALUE; // no crashing
|
||||||
@@ -687,7 +567,13 @@ void MediaReader::LateNoticeReceived(
|
|||||||
SetEventLatency(fDownstreamLatency + fInternalLatency);
|
SetEventLatency(fDownstreamLatency + fInternalLatency);
|
||||||
break;
|
break;
|
||||||
case B_DECREASE_PRECISION:
|
case B_DECREASE_PRECISION:
|
||||||
// What you want us to give you fewer bits or something?
|
// XXX : shorten our buffer period
|
||||||
|
// We could opt to just not wait but we should
|
||||||
|
// probably gradually shorten the period so we
|
||||||
|
// don't starve others. Also, we need to make
|
||||||
|
// sure we are catching up! We may have some sort
|
||||||
|
// of time goal for how long it takes us to
|
||||||
|
// catch up, as well.
|
||||||
break;
|
break;
|
||||||
case B_DROP_DATA:
|
case B_DROP_DATA:
|
||||||
// Okay you asked for it, we'll skip ahead in the file!
|
// Okay you asked for it, we'll skip ahead in the file!
|
||||||
|
|||||||
@@ -74,8 +74,9 @@ BMediaNode * MediaReaderAddOn::InstantiateNodeFor(
|
|||||||
fprintf(stderr,"<- NULL\n");
|
fprintf(stderr,"<- NULL\n");
|
||||||
return 0; // we refuse to crash because you were stupid
|
return 0; // we refuse to crash because you were stupid
|
||||||
}
|
}
|
||||||
size_t defaultChunkSize = size_t(8192); // XXX: read from add-on's attributes
|
// XXX: read from add-on's attributes
|
||||||
float defaultBitRate = 800000;
|
size_t defaultChunkSize = size_t(8192); // 8192 bytes = 8 Kilobytes
|
||||||
|
float defaultBitRate = 2048; // = 2048 kilobits/millisec = 256000 Kilobytes/sec
|
||||||
MediaReader * node
|
MediaReader * node
|
||||||
= new MediaReader(defaultChunkSize,
|
= new MediaReader(defaultChunkSize,
|
||||||
defaultBitRate,
|
defaultBitRate,
|
||||||
|
|||||||
Reference in New Issue
Block a user