[Theora] Trying to do windows encoding dll

Florian Geyer florian-geyer at web.de
Wed Feb 9 14:04:45 PST 2005


Hi everybody, me again.
I'm trying to write my own VFW-like dll... It doesn't need to do much.
1.) compress a single frame and give it back to the host application
2.) host applications sends the frame
3.) client application receives frame
4.) client application tells the dll to decompress the data

So if I try to do this, something is going wrong...
Perhaps someone could have a look at my source code and tell me what?
After encoded the frame, the body_length attribute of the ogg_page op
from encode has some reasonable value. But sizeof(*op->body) returns 1...

The output I get is a big black screen...

Any suggestions?

Thanks and best regards,
	Florian
	(Stuttgart, GERMANY)



#include <windows.h>
#include "theora/theora.h"

theora_state enc_state;
int enc_width, enc_height;
ogg_stream_state enc_stream;

theora_state dec_state;
int dec_width, dec_height;
ogg_stream_state dec_stream;

__declspec (dllexport) void startenc(int width, int height, int bitrate)
{
  ogg_stream_init(&enc_stream, 290482);

  enc_width = width;
  enc_height = height;

  theora_info ti;
  theora_info_init(&ti);
  ti.width=width;
  ti.height=height;
// must be /16
  ti.frame_width=width;
  ti.frame_height=height;
  ti.offset_x=0;
  ti.offset_y=0;
  ti.colorspace=OC_CS_UNSPECIFIED;
  ti.target_bitrate=bitrate;
  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=bitrate*1.5;
  ti.keyframe_auto_threshold=80;
  ti.keyframe_mindistance=8;
  ti.noise_sensitivity=1;

  theora_encode_init(&enc_state,&ti);
  theora_info_clear(&ti);
}

__declspec (dllexport) encode(signed char *yuvframe, ogg_page *op)
{
  while (ogg_stream_pageout(&enc_stream, op) == 0)
  {
    yuv_buffer yuv_enc;

    yuv_enc.y_width=enc_width;
    yuv_enc.y_height=enc_height;
    yuv_enc.y_stride=enc_width;

    yuv_enc.uv_width=enc_width/2;
    yuv_enc.uv_height=enc_height/2;
    yuv_enc.uv_stride=enc_width/2;

    yuv_enc.y=yuvframe;
    yuv_enc.u=yuvframe+enc_width*enc_height;
    yuv_enc.v=yuvframe+enc_width*enc_height*5/4;

    theora_encode_YUVin(&enc_state,&yuv_enc);

    ogg_packet opacket;
    theora_encode_packetout(&enc_state,0,&opacket);

    ogg_stream_packetin(&enc_stream,&opacket);
  }
}

__declspec (dllexport) void stopenc()
{
  theora_clear(&enc_state);
  ogg_stream_clear(&enc_stream);
}

__declspec (dllexport) void startdec(int width, int height, int bitrate)
{
  ogg_stream_init(&dec_stream, 290482);

  dec_width = width;
  dec_height = height;

  theora_info ti;
  theora_info_init(&ti);
  ti.width=width;
  ti.height=height;
// must be /16
  ti.frame_width=width;
  ti.frame_height=height;
  ti.offset_x=0;
  ti.offset_y=0;
  ti.colorspace=OC_CS_UNSPECIFIED;
  ti.target_bitrate=bitrate;
  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=bitrate*1.5;
  ti.keyframe_auto_threshold=80;
  ti.keyframe_mindistance=8;
  ti.noise_sensitivity=1;

  theora_decode_init(&dec_state,&ti);
  theora_info_clear(&ti);
}

__declspec (dllexport) void decode(signed char *yuvframe, ogg_page *op)
{
  ogg_packet ipacket;
  ogg_stream_pagein(&dec_stream, op);
  theora_decode_packetin(&dec_state,&ipacket); 
  theora_decode_YUVout(&dec_state, yuvframe);
}

__declspec (dllexport) void stopdec()
{
  theora_clear(&dec_state);
  ogg_stream_clear(&dec_stream);
}

BOOL APIENTRY DllMain (HINSTANCE hInst     /* Library instance handle. */ ,
                       DWORD reason        /* Reason this function is being
called. */ ,
                       LPVOID reserved     /* Not used. */ )
{
  return TRUE;
}



More information about the Theora mailing list