00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include "stdafx.h"
00033 #include "theoraencoder.h"
00034
00035 TheoraEncoder::TheoraEncoder(void)
00036 {
00037 }
00038
00039 TheoraEncoder::~TheoraEncoder(void)
00040 {
00041 }
00042
00045 StampedOggPacket** TheoraEncoder::initCodec(theora_info inTheoraInfo)
00046 {
00047 mTheoraInfo = inTheoraInfo;
00048 theora_encode_init(&mTheoraState,&mTheoraInfo);
00049
00050 StampedOggPacket** locHeaders = new StampedOggPacket*[3];
00051
00052 ogg_packet locOldPacket;
00053 theora_encode_header(&mTheoraState, &locOldPacket);
00054
00055 locHeaders[0] = oldToNewPacket(&locOldPacket);
00056
00057 theora_comment_init(&mTheoraComment);
00058 theora_encode_comment(&mTheoraComment, &locOldPacket);
00059
00060 locHeaders[1] = oldToNewPacket(&locOldPacket);
00061
00062 theora_encode_tables(&mTheoraState, &locOldPacket);
00063
00064 locHeaders[2] = oldToNewPacket(&locOldPacket);
00065
00066
00067 return locHeaders;
00068 }
00069
00070
00074 StampedOggPacket* TheoraEncoder::oldToNewPacket(ogg_packet* inOldPacket)
00075 {
00076 const unsigned char NOT_USED = 0;
00077
00078
00079 unsigned char* locBuff = new unsigned char[inOldPacket->bytes];
00080 memcpy((void*)locBuff, (const void*)inOldPacket->packet, inOldPacket->bytes);
00081
00082 StampedOggPacket* locOggPacket = new StampedOggPacket(locBuff, inOldPacket->bytes, false, false, NOT_USED, inOldPacket->granulepos, StampedOggPacket::OGG_END_ONLY);
00083 return locOggPacket;
00084
00085 }
00086
00089 StampedOggPacket* TheoraEncoder::encodeTheora(yuv_buffer* inYUVBuffer)
00090 {
00091 const int NOT_LAST_FRAME = 0;
00092
00093 int retVal = 0;
00094
00095
00096 ogg_packet locOldOggPacket;
00097 retVal = theora_encode_YUVin(&mTheoraState, inYUVBuffer);
00098
00099 if (retVal != 0) {
00100
00101 return NULL;
00102 }
00103
00104
00105 retVal = theora_encode_packetout(&mTheoraState, NOT_LAST_FRAME, &locOldOggPacket);
00106
00107 if (retVal != 1) {
00108
00109 return NULL;
00110 }
00111
00112 return oldToNewPacket(&locOldOggPacket);
00113
00114 }