use user_data for ogg_packet and pass raw data pointer through chunkBuffer

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@9495 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
shatty 2004-10-25 08:22:59 +00:00
parent a13f233057
commit 8b6368d31b
12 changed files with 38 additions and 37 deletions

View File

@ -0,0 +1,10 @@
#ifndef _OGG_FORMATS_H
#define _OGG_FORMATS_H
//! for use in media_misc_description.file_format
const uint32 OGG_FILE_FORMAT = 'OggS';
//! for use in media_header.user_data_type
const uint32 OGG_PACKET_DATA_TYPE = 'OggP';
#endif _OGG_FORMATS_H

View File

@ -2,6 +2,7 @@
#include "OggSpeexSeekable.h"
#include "OggTobiasSeekable.h"
#include "OggVorbisSeekable.h"
#include "OggFormats.h"
#include <Autolock.h>
#include <stdio.h>
@ -247,7 +248,7 @@ OggSeekable::GetStreamInfo(int64 *frameCount, bigtime_t *duration,
// get the format for the description
media_format_description description;
description.family = B_MISC_FORMAT_FAMILY;
description.u.misc.file_format = 'OggS';
description.u.misc.file_format = OGG_FILE_FORMAT;
description.u.misc.codec = four_bytes;
BMediaFormats formats;
result = formats.InitCheck();
@ -448,21 +449,25 @@ OggSeekable::Seek(uint32 seekTo, int64 *frame, bigtime_t *time)
return B_OK;
}*/
status_t
OggSeekable::GetNextChunk(void **chunkBuffer, int32 *chunkSize,
media_header *mediaHeader)
{
ogg_packet packet;
BAutolock autolock(fPositionLock);
status_t result = GetPacket(&fChunkPacket);
status_t result = GetPacket(&packet);
*chunkBuffer = packet.packet;
*chunkSize = packet.bytes;
packet.packet = NULL;
assert(sizeof(ogg_packet) <= sizeof(mediaHeader->user_data));
mediaHeader->user_data_type = OGG_PACKET_DATA_TYPE;
memcpy(mediaHeader->user_data, &packet, sizeof(ogg_packet));
if (result != B_OK) {
TRACE("OggSeekable::GetNextChunk failed: GetPacket = %s\n", strerror(result));
return result;
}
*chunkBuffer = &fChunkPacket;
*chunkSize = sizeof(fChunkPacket);
if (fChunkPacket.granulepos > 0) {
fCurrentFrame = fChunkPacket.granulepos - fFirstGranulepos;
if (packet.granulepos > 0) {
fCurrentFrame = packet.granulepos - fFirstGranulepos;
fCurrentTime = (bigtime_t)((fCurrentFrame * 1000000LL) / fFrameRate);
mediaHeader->start_time = fCurrentTime;
} else {

View File

@ -40,7 +40,6 @@ protected:
// subclass pull input function
status_t GetPacket(ogg_packet * packet);
ogg_packet fChunkPacket;
protected:
int64 fCurrentFrame;

View File

@ -4,6 +4,7 @@
#include <MediaFormats.h>
#include <ogg/ogg.h>
#include <string.h>
#include <OggFormats.h>
/*
* speex descriptions/formats
@ -15,7 +16,7 @@ speex_description()
{
media_format_description description;
description.family = B_MISC_FORMAT_FAMILY;
description.u.misc.file_format = 'OggS';
description.u.misc.file_format = OGG_FILE_FORMAT;
description.u.misc.codec = 'Spee';
return description;
}

View File

@ -179,18 +179,3 @@ OggSpeexSeekable::GetStreamInfo(int64 *frameCount, bigtime_t *duration,
return B_OK;
}
status_t
OggSpeexSeekable::GetNextChunk(void **chunkBuffer, int32 *chunkSize,
media_header *mediaHeader)
{
status_t result = inherited::GetNextChunk(chunkBuffer, chunkSize, mediaHeader);
if (result != B_OK) {
TRACE("OggSpeexSeekable::GetNextChunk failed: GetNextChunk = %s\n", strerror(result));
return result;
}
*chunkSize = ((ogg_packet*)*chunkBuffer)->bytes;
*chunkBuffer = ((ogg_packet*)*chunkBuffer)->packet;
return B_OK;
}

View File

@ -16,8 +16,6 @@ public:
virtual status_t GetStreamInfo(int64 *frameCount, bigtime_t *duration,
media_format *format);
virtual status_t GetNextChunk(void **chunkBuffer, int32 *chunkSize,
media_header *mediaHeader);
};

View File

@ -3,6 +3,7 @@
#include "OggTheoraStream.h"
#include "OggTobiasStream.h"
#include "OggVorbisStream.h"
#include "OggFormats.h"
#include <Autolock.h>
#include <stdio.h>
@ -107,7 +108,7 @@ OggStream::GetStreamInfo(int64 *frameCount, bigtime_t *duration,
// get the format for the description
media_format_description description;
description.family = B_MISC_FORMAT_FAMILY;
description.u.misc.file_format = 'OggS';
description.u.misc.file_format = OGG_FILE_FORMAT;
description.u.misc.codec = four_bytes;
BMediaFormats formats;
result = formats.InitCheck();

View File

@ -4,6 +4,7 @@
#include <MediaFormats.h>
#include <ogg/ogg.h>
#include <string.h>
#include <OggFormats.h>
/*
* theora descriptions/formats
@ -15,7 +16,7 @@ theora_description()
{
media_format_description description;
description.family = B_MISC_FORMAT_FAMILY;
description.u.misc.file_format = 'OggS';
description.u.misc.file_format = OGG_FILE_FORMAT;
description.u.misc.codec = 'theo';
return description;
}

View File

@ -4,6 +4,7 @@
#include <MediaFormats.h>
#include <ogg/ogg.h>
#include <string.h>
#include "OggFormats.h"
/*
* tobias descriptions/formats
@ -47,7 +48,7 @@ tobias_text_description()
{
media_format_description description;
description.family = B_MISC_FORMAT_FAMILY;
description.u.misc.file_format = 'OggS';
description.u.misc.file_format = OGG_FILE_FORMAT;
description.u.misc.codec = 'text';
return description;
}

View File

@ -266,8 +266,6 @@ OggTobiasSeekable::GetNextChunk(void **chunkBuffer, int32 *chunkSize,
TRACE("OggTobiasSeekable::GetNextChunk failed: GetNextChunk = %s\n", strerror(result));
return result;
}
*chunkSize = ((ogg_packet*)*chunkBuffer)->bytes;
*chunkBuffer = ((ogg_packet*)*chunkBuffer)->packet;
bool keyframe = ((uint*)chunkBuffer)[0] & (1 << 3); // ??
if (fMediaFormat.type == B_MEDIA_ENCODED_VIDEO) {
mediaHeader->type = fMediaFormat.type;

View File

@ -4,6 +4,7 @@
#include <MediaFormats.h>
#include <ogg/ogg.h>
#include <string.h>
#include "OggFormats.h"
/*
* vorbis descriptions/formats
@ -15,7 +16,7 @@ vorbis_description()
{
media_format_description description;
description.family = B_MISC_FORMAT_FAMILY;
description.u.misc.file_format = 'OggS';
description.u.misc.file_format = OGG_FILE_FORMAT;
description.u.misc.codec = 'vorb';
return description;
}

View File

@ -184,13 +184,13 @@ VorbisDecoder::Decode(void *buffer, int64 *frameCount,
status_t status = GetNextChunk(&chunkBuffer, &chunkSize, &mh);
if (status == B_LAST_BUFFER_ERROR) {
goto done;
}
}
if (status != B_OK) {
TRACE("VorbisDecoder::Decode: GetNextChunk failed\n");
return status;
}
if (chunkSize != sizeof(ogg_packet)) {
TRACE("VorbisDecoder::Decode: chunk not ogg_packet-sized\n");
if (mh.user_data_type != OGG_PACKET_DATA_TYPE) {
TRACE("VorbisDecoder::Decode: chunk missing ogg_packet data");
return B_ERROR;
}
if (!synced) {
@ -199,8 +199,9 @@ VorbisDecoder::Decode(void *buffer, int64 *frameCount,
synced = true;
}
}
ogg_packet * packet = static_cast<ogg_packet*>(chunkBuffer);
if (vorbis_synthesis(&fBlock,packet)==0) {
ogg_packet * packet = reinterpret_cast<ogg_packet*>(mh.user_data);
packet->packet = static_cast<unsigned char *>(chunkBuffer);
if (vorbis_synthesis(&fBlock, packet)==0) {
vorbis_synthesis_blockin(&fDspState,&fBlock);
}
}