[xiph-commits] r6934 - in trunk/oggdsf/src/lib/codecs/theora:

illiminable at dactyl.lonelymoon.com illiminable
Wed Jun 30 01:06:35 PDT 2004


filters/dsfTheoraEncoder libs/libOOTheora
Message-ID: <20040630080635.BD4A19AAAD at dactyl.lonelymoon.com>

Author: illiminable
Date: Wed Jun 30 01:06:35 2004
New Revision: 6934

Modified:
trunk/oggdsf/src/lib/codecs/theora/filters/dsfTheoraEncoder/TheoraEncodeInputPin.cpp
trunk/oggdsf/src/lib/codecs/theora/filters/dsfTheoraEncoder/TheoraEncodeInputPin.h
trunk/oggdsf/src/lib/codecs/theora/libs/libOOTheora/TheoraEncoder.cpp
Log:
* Encoder for theora now kind of works... fixed some bad pointer and buffer stuff.
* Crashes though after about 10 seconds of video.

Modified: trunk/oggdsf/src/lib/codecs/theora/filters/dsfTheoraEncoder/TheoraEncodeInputPin.cpp
===================================================================
--- trunk/oggdsf/src/lib/codecs/theora/filters/dsfTheoraEncoder/TheoraEncodeInputPin.cpp	2004-06-30 05:07:56 UTC (rev 6933)
+++ trunk/oggdsf/src/lib/codecs/theora/filters/dsfTheoraEncoder/TheoraEncodeInputPin.cpp	2004-06-30 08:06:21 UTC (rev 6934)
@@ -38,6 +38,7 @@


{
+	debugLog.open("g:\\logs\\theoencfilt.log", ios_base::out);
mYUV.y = NULL;
mYUV.u = NULL;
mYUV.v = NULL;
@@ -46,6 +47,7 @@

TheoraEncodeInputPin::~TheoraEncodeInputPin(void)
{
+	debugLog.close();
DestroyCodec();
delete mYUV.y;
delete mYUV.u;
@@ -55,6 +57,7 @@


HRESULT TheoraEncodeInputPin::deliverData(LONGLONG inStart, LONGLONG inEnd, unsigned char* inBuf, unsigned long inNumBytes) {
+	debugLog <<" deliverData : "<<inStart<<" - "<<inEnd<<"  :: size = "<<inNumBytes<<endl;
//Get a pointer to a new sample stamped with our time
IMediaSample* locSample;
HRESULT locHR = mOutputPin->GetDeliveryBuffer(&locSample, &inStart, &inEnd, NULL);
@@ -86,7 +89,7 @@
} else {
}
}
-
+		debugLog<<"deliverData : SUCCESS"<<endl;
return S_OK;
} else {
throw 0;
@@ -102,6 +105,7 @@
LONGLONG locFrameEnd = 0;
HRESULT locHR = S_OK;
if (!mBegun) {
+		debugLog<<"encodeData : First time"<<endl;
mBegun = true;

StampedOggPacket** locHeaders;
@@ -127,11 +131,13 @@
//	memcpy((void*)locBuffer, (const void*)(inYUVBuffer->y + (inYUVBuffer->y_stride * (line))), inYUVBuffer->y_width);
//	locBuffer += inYUVBuffer->y_width;

-	unsigned char* locUptoPtr = inBuf;  //View only... don't delete locUptoPtr
+	unsigned char* locSourceUptoPtr = inBuf;  //View only... don't delete locUptoPtr

+	char* locDestUptoPtr = mYUV.y;
for (long line = 0; line < mYUV.y_height; line++) {
-		memcpy((void*)mYUV.y, (const void*)locUptoPtr, mYUV.y_width);
-		locUptoPtr += mYUV.y_width;
+		memcpy((void*)locDestUptoPtr, (const void*)locSourceUptoPtr, mYUV.y_width);
+		locSourceUptoPtr += mYUV.y_width;
+		locDestUptoPtr += mYUV.y_width;
}

//	if (mWidth > inYUVBuffer->y_width) {
@@ -151,9 +157,11 @@
//	memcpy((void*)locBuffer, (const void*)(inYUVBuffer->v + (inYUVBuffer->uv_stride * (line))), inYUVBuffer->uv_width);
//	locBuffer += inYUVBuffer->uv_width;

+	locDestUptoPtr = mYUV.v;
for (long line = 0; line < mYUV.uv_height; line++) {
-		memcpy((void*)mYUV.v, (const void*)locUptoPtr, mYUV.uv_width);
-		locUptoPtr += mYUV.uv_width;
+		memcpy((void*)locDestUptoPtr, (const void*)locSourceUptoPtr, mYUV.uv_width);
+		locSourceUptoPtr += mYUV.uv_width;
+		locDestUptoPtr += mYUV.uv_width;

}
//	if (mWidth/2 > inYUVBuffer->uv_width) {
@@ -173,9 +181,11 @@
//	memcpy((void*)locBuffer, (const void*)(inYUVBuffer->u + (inYUVBuffer->uv_stride * (line))), inYUVBuffer->uv_width);
//	locBuffer += inYUVBuffer->uv_width;

+	locDestUptoPtr = mYUV.u;
for (long line = 0; line < mYUV.uv_height; line++) {
-		memcpy((void*)mYUV.u, (const void*)locUptoPtr, mYUV.uv_width);
-		locUptoPtr += mYUV.uv_width;
+		memcpy((void*)locDestUptoPtr, (const void*)locSourceUptoPtr, mYUV.uv_width);
+		locSourceUptoPtr += mYUV.uv_width;
+		locDestUptoPtr += mYUV.uv_width;
}
//	if (mWidth/2 > inYUVBuffer->uv_width) {
//		memset((void*)locBuffer, 0, (mWidth/2) - inYUVBuffer->uv_width);
@@ -198,100 +208,9 @@

return deliverData(locFrameStart, locFrameEnd, locPacket->packetData(), locPacket->packetSize());

-
-
-
-	//float* locFloatBuf = new float[inNumBytes/2];
-	//short locTempShort = 0;
-	//float locTempFloat = 0;
-
-	////__int64 locGranPos = 0;
-	////locGranPos = fish_sound_get_frameno(mFishSound);
-	////Removed the hack
-	////fish_sound_command(mFishSound, 7, &locGranPos, sizeof(__int64));
-	////
-
-	////mUptoFrame = locGranPos;
-	////__int64 locTemp = ((FishSoundVorbisInfo*)mFishSound->codec_data)->vd.pcm_returned;
-	//for (int i = 0; i < inNumBytes; i += 2) {
-	//	locTempShort = *((short*)(inBuf + i));
-	//	locTempFloat = (float)locTempShort;
-	//	locTempFloat /= 32767.0;
-	//	locFloatBuf[i/2] = locTempFloat;;
-	//}
-	////FIX::: The 2 is the size of a sample ie 16 bits
-	//long locErr = fish_sound_encode(mFishSound, (float**)locFloatBuf, inNumBytes/(mFishInfo.channels*2));
-	//delete locFloatBuf;
-	////FIX::: Do something here ?
-	//if (locErr < 0) {
-	//
-	//} else {
-	//
-	//}
-
}
bool TheoraEncodeInputPin::ConstructCodec() {
-//	typedef struct {
-//  ogg_uint32_t  width;
-//  ogg_uint32_t  height;
-//  ogg_uint32_t  frame_width;
-//  ogg_uint32_t  frame_height;
-//  ogg_uint32_t  offset_x;
-//  ogg_uint32_t  offset_y;
-//  ogg_uint32_t  fps_numerator;
-//  ogg_uint32_t  fps_denominator;
-//  ogg_uint32_t  aspect_numerator;
-//  ogg_uint32_t  aspect_denominator;
-//  theora_colorspace colorspace;
-//  int           target_bitrate;
-//  int           quality;
-//  int           quick_p;  /* quick encode/decode */
-//
-//  /* decode only */
-//  unsigned char version_major;
-//  unsigned char version_minor;
-//  unsigned char version_subminor;
-//
-//  void *codec_setup;
-//
-//  /* encode only */
-//  int           dropframes_p;
-//  int           keyframe_auto_p;
-//  ogg_uint32_t  keyframe_frequency;
-//  ogg_uint32_t  keyframe_frequency_force;  /* also used for decode init to
-//                                              get granpos shift correct */
-//  ogg_uint32_t  keyframe_data_target_bitrate;
-//  ogg_int32_t   keyframe_auto_threshold;
-//  ogg_uint32_t  keyframe_mindistance;
-//  ogg_int32_t   noise_sensitivity;
-//  ogg_int32_t   sharpness;
-//
-//} theora_info;

-//theora_info_init(&ti);
-//  ti.width=video_x;
-//  ti.height=video_y;
-//  ti.frame_width=frame_x;
-//  ti.frame_height=frame_y;
-//  ti.offset_x=frame_x_offset;
-//  ti.offset_y=frame_y_offset;
-//  ti.fps_numerator=video_hzn;
-//  ti.fps_denominator=video_hzd;
-//  ti.aspect_numerator=video_an;
-//  ti.aspect_denominator=video_ad;
-//  ti.colorspace=OC_CS_UNSPECIFIED;
-//  ti.target_bitrate=video_r;
-//  ti.quality=video_q;
-//
-//  ti.dropframes_p=0;
-//  ti.quick_p=1;
-//  ti.keyframe_auto_p=1;
-//  ti.keyframe_frequency=64;
-//  ti.keyframe_frequency_force=64;
-//  ti.keyframe_data_target_bitrate=video_r*1.5;
-//  ti.keyframe_auto_threshold=80;
-//  ti.keyframe_mindistance=8;
-//  ti.noise_sensitivity=1;

theora_info_init(&mTheoraInfo);

@@ -303,6 +222,7 @@
mYUV.uv_width		=	mYUV.uv_stride
=	mWidth/2;

+
mTheoraInfo.height	=	mHeight
=	mYUV.y_height
=	mVideoFormat->bmiHeader.biHeight;
@@ -313,6 +233,8 @@
mYUV.u				=	new char[(mHeight * mWidth)/4];
mYUV.v				=	new char[(mHeight * mWidth)/4];

+	debugLog<<"Width =y_w = y_s = "<<mWidth<<" ::: "<<"Height=y_h= "<<mHeight<<endl;
+	debugLog<<"uv_w=uv_s= "<<mYUV.uv_stride<<" ::: " <<"uv_height = "<<mYUV.uv_height<<endl;
mTheoraInfo.frame_width=mVideoFormat->bmiHeader.biWidth;
mTheoraInfo.frame_height=mVideoFormat->bmiHeader.biHeight;
mTheoraInfo.offset_x=0;
@@ -322,48 +244,29 @@
//HACK:::Bit of a hack to convert dshow nanos to a fps num/denom.
unsigned long locNum = (((double)10000000) / ((double)mVideoFormat->AvgTimePerFrame)) + (double)0.5;

+	debugLog<<"FPS = "<<locNum<<endl;
mTheoraInfo.fps_numerator = locNum;
mTheoraInfo.fps_denominator = 1;
//I don't think this is right !
-	mTheoraInfo.aspect_numerator=mVideoFormat->bmiHeader.biWidth;//video_an;
-	mTheoraInfo.aspect_denominator=mVideoFormat->bmiHeader.biHeight;//video_ad;
+	mTheoraInfo.aspect_numerator=1;//mVideoFormat->bmiHeader.biWidth;//video_an;
+	mTheoraInfo.aspect_denominator=1;//mVideoFormat->bmiHeader.biHeight;//video_ad;
//
mTheoraInfo.colorspace=OC_CS_UNSPECIFIED;
-	mTheoraInfo.target_bitrate=mVideoFormat->dwBitRate;
+	mTheoraInfo.target_bitrate=1500000; //mVideoFormat->dwBitRate;
+
//Hard code for now
-	mTheoraInfo.quality=16; //video_q;
+	mTheoraInfo.quality=63; //video_q;

mTheoraInfo.dropframes_p=0;
mTheoraInfo.quick_p=1;
mTheoraInfo.keyframe_auto_p=1;
mTheoraInfo.keyframe_frequency=64;
mTheoraInfo.keyframe_frequency_force=64;
-	mTheoraInfo.keyframe_data_target_bitrate=mVideoFormat->dwBitRate*1.5;
+	mTheoraInfo.keyframe_data_target_bitrate=mTheoraInfo.target_bitrate*1.5;
mTheoraInfo.keyframe_auto_threshold=80;
mTheoraInfo.keyframe_mindistance=8;
mTheoraInfo.noise_sensitivity=1;

-
-
-
-
-
-
-
-	//mFishInfo.channels = mWaveFormat->nChannels;
-	//mFishInfo.format = FISH_SOUND_VORBIS;
-	//mFishInfo.samplerate = mWaveFormat->nSamplesPerSec;
-
-
-	//mFishInfo.format = FISH_SOUND_VORBIS;
-	//mFishSound = fish_sound_new (FISH_SOUND_ENCODE, &mFishInfo);
-
-	//int i = 1;
-	////FIX::: Use new API for interleave setting
-	//fish_sound_command(mFishSound, FISH_SOUND_SET_INTERLEAVE, &i, sizeof(int));
-
-	//fish_sound_set_encoded_callback (mFishSound, VorbisEncodeInputPin::VorbisEncoded, this);
-	//FIX::: Proper return value
return true;

}
@@ -373,62 +276,7 @@
}


-//Encoded callback
-//int TheoraEncodeInputPin::VorbisEncoded (FishSound* inFishSound, unsigned char* inPacketData, long inNumBytes, void* inThisPointer)
-//{
-//
-//	VorbisEncodeInputPin* locThis = reinterpret_cast<VorbisEncodeInputPin*> (inThisPointer);
-//	VorbisEncodeFilter* locFilter = reinterpret_cast<VorbisEncodeFilter*>(locThis->m_pFilter);
-//
-//
-//	//Time stamps are granule pos not directshow times
-//
-//	LONGLONG locFrameStart = locThis->mUptoFrame;
-//	LONGLONG locFrameEnd	= locThis->mUptoFrame
-//							= fish_sound_get_frameno(locThis->mFishSound);
-//	//Get a pointer to a new sample stamped with our time
-//	IMediaSample* locSample;
-//	HRESULT locHR = locThis->mOutputPin->GetDeliveryBuffer(&locSample, &locFrameStart, &locFrameEnd, NULL);
-//
-//	if (FAILED(locHR)) {
-//		//We get here when the application goes into stop mode usually.
-//		return locHR;
-//	}
-//
-//	BYTE* locBuffer = NULL;
-//
-//
-//	//Make our pointers set to point to the samples buffer
-//	locSample->GetPointer(&locBuffer);
-//
-//
-//
-//	if (locSample->GetSize() >= inNumBytes) {
-//
-//		memcpy((void*)locBuffer, (const void*)inPacketData, inNumBytes);
-//
-//		//Set the sample parameters.
-//		locThis->SetSampleParams(locSample, inNumBytes, &locFrameStart, &locFrameEnd);
-//
-//		{
-//			CAutoLock locLock(locThis->m_pLock);
-//
-//			//Add a reference so it isn't deleted en route.
-//			//locSample->AddRef();
-//			HRESULT locHR = locThis->mOutputPin->mDataQueue->Receive(locSample);						//->DownstreamFilter()->Receive(locSample);
-//			if (locHR != S_OK) {
-//
-//			} else {
-//			}
-//		}
-//
-//		return 0;
-//	} else {
-//		throw 0;
-//	}
-//}

-
HRESULT TheoraEncodeInputPin::SetMediaType(const CMediaType* inMediaType) {
AbstractVideoEncodeInputPin::SetMediaType(inMediaType);


Modified: trunk/oggdsf/src/lib/codecs/theora/filters/dsfTheoraEncoder/TheoraEncodeInputPin.h
===================================================================
--- trunk/oggdsf/src/lib/codecs/theora/filters/dsfTheoraEncoder/TheoraEncodeInputPin.h	2004-06-30 05:07:56 UTC (rev 6933)
+++ trunk/oggdsf/src/lib/codecs/theora/filters/dsfTheoraEncoder/TheoraEncodeInputPin.h	2004-06-30 08:06:21 UTC (rev 6934)
@@ -33,10 +33,11 @@
#include "theoraencoderdllstuff.h"
#include "TheoraEncoder.h"
#include "theora/theora.h"
-//#include "AbstractVideoEncodeInputPin.h"
-//#include "TheoraEncodeInputPin.h"

-//#include "TheoraEncodeFilter.h"
+//DEBUG ONLY
+#include <fstream>
+using namespace std;
+//

class TheoraEncodeOutputPin;
class TheoraEncodeInputPin
@@ -68,5 +69,9 @@
theora_info mTheoraInfo;
yuv_buffer mYUV;

+	//DEBUG ONLY
+	fstream debugLog;
+	//
+

};

Modified: trunk/oggdsf/src/lib/codecs/theora/libs/libOOTheora/TheoraEncoder.cpp
===================================================================
--- trunk/oggdsf/src/lib/codecs/theora/libs/libOOTheora/TheoraEncoder.cpp	2004-06-30 05:07:56 UTC (rev 6933)
+++ trunk/oggdsf/src/lib/codecs/theora/libs/libOOTheora/TheoraEncoder.cpp	2004-06-30 08:06:21 UTC (rev 6934)
@@ -96,11 +96,12 @@
StampedOggPacket* TheoraEncoder::encodeTheora(yuv_buffer* inYUVBuffer) {
const int NOT_LAST_FRAME = 0;
const int IS_LAST_FRAME = 1;
+	int retVal = 0;

ogg_packet locOldOggPacket;
-	theora_encode_YUVin(&mTheoraState, inYUVBuffer);
+	retVal = theora_encode_YUVin(&mTheoraState, inYUVBuffer);

-	theora_encode_packetout(&mTheoraState, NOT_LAST_FRAME, &locOldOggPacket);
+	retVal = theora_encode_packetout(&mTheoraState, NOT_LAST_FRAME, &locOldOggPacket);

return oldToNewPacket(&locOldOggPacket);




More information about the commits mailing list