00001
00002
00003
00004
00005
00006 #include <e32base.h>
00007 #include <oggutil.h>
00008 #include "OggUtilBody.h"
00009
00010
00011 #ifdef SYMBIAN_CODEC_FLOAT_POINT
00012 #include "ogg/ogg.h"
00013 #else
00014 #include "tremor/ogg.h"
00015 #endif
00016
00017
00018
00019 void OggUtil::Make_ogg_page(const TOggPage& aPage, ogg_page& aOggPage)
00020 {
00021
00022 #ifdef SYMBIAN_CODEC_FLOAT_POINT
00023 aOggPage.header = const_cast<unsigned char*>(aPage.iHead.Ptr());
00024 aOggPage.body = const_cast<unsigned char*>(aPage.iBody.Ptr());
00025 #else
00026 aOggPage.header = reinterpret_cast<ogg_reference*>(const_cast<unsigned char*>(aPage.iHead.Ptr()));
00027 aOggPage.body = reinterpret_cast<ogg_reference*>(const_cast<unsigned char*>(aPage.iBody.Ptr()));
00028 #endif
00029 aOggPage.header_len = aPage.iHead.Length();
00030 aOggPage.body_len = aPage.iBody.Length();
00031 }
00032
00033 void OggUtil::Make_ogg_packet(const TOggPacket& aSrc, ogg_packet& aDst)
00034 {
00035 #ifdef SYMBIAN_CODEC_FLOAT_POINT
00036 aDst.packet = const_cast<unsigned char*>(aSrc.iData.Ptr());
00037 #else
00038 aDst.packet = reinterpret_cast<ogg_reference*>(const_cast<unsigned char*>(aSrc.iData.Ptr()));
00039 #endif
00040
00041 aDst.bytes = aSrc.iData.Length();
00042 aDst.b_o_s = aSrc.iBOS;
00043 aDst.e_o_s = aSrc.iEOS;
00044 aDst.granulepos = I64LOW(aSrc.iGranulePos) | ((TInt64)(I64HIGH(aSrc.iGranulePos))<<32);
00045 aDst.packetno = I64LOW(aSrc.iPacketNo) | (((TInt64)I64HIGH(aSrc.iPacketNo))<<32);
00046 }
00047
00048 void OggUtil::MakeOggPage(const ogg_page& aSrc, TOggPage& aDest)
00049 {
00050 aDest.iHead.Set(reinterpret_cast<unsigned char*>(aSrc.header), aSrc.header_len, aSrc.header_len);
00051 aDest.iBody.Set(reinterpret_cast<unsigned char*>(aSrc.body), aSrc.body_len, aSrc.body_len);
00052 }
00053
00054 void OggUtil::MakeOggPacket(const ogg_packet& aSrc, TOggPacket& aDest)
00055 {
00056 aDest.iBOS = aSrc.b_o_s;
00057 aDest.iEOS = aSrc.e_o_s;
00058 aDest.iGranulePos = MAKE_TINT64(aSrc.granulepos>>32,aSrc.granulepos&0xffffffffL);
00059 aDest.iPacketNo = MAKE_TINT64(aSrc.packetno>>32>>32,aSrc.packetno&0xffffffffL);
00060 aDest.iData.Set(reinterpret_cast<unsigned char*>(aSrc.packet), aSrc.bytes, aSrc.bytes);
00061 }
00062
00063 EXPORT_C TOggPage::TOggPage(const TPtr8& aHead, const TPtr8& aBody)
00064 : iHead(aHead), iBody(aBody)
00065 {
00066 }
00067
00068 EXPORT_C TOggPage::TOggPage()
00069 : iHead(NULL, 0), iBody(NULL, 0)
00070 {
00071 }
00072
00073 EXPORT_C TInt TOggPage::Version() const
00074 {
00075 ogg_page op;
00076 OggUtil::Make_ogg_page(*this, op);
00077 return ogg_page_version(&op);
00078 }
00079
00080 EXPORT_C TBool TOggPage::Continued() const
00081 {
00082 ogg_page op;
00083 OggUtil::Make_ogg_page(*this, op);
00084 return ogg_page_continued(&op);
00085 }
00086
00087 EXPORT_C TInt TOggPage::Packets() const
00088 {
00089 ogg_page op;
00090 OggUtil::Make_ogg_page(*this, op);
00091 return ogg_page_packets(&op);
00092 }
00093
00094 EXPORT_C TInt TOggPage::BOS() const
00095 {
00096 ogg_page op;
00097 OggUtil::Make_ogg_page(*this, op);
00098 return ogg_page_bos(&op);
00099 }
00100
00101 EXPORT_C TInt TOggPage::EOS() const
00102 {
00103 ogg_page op;
00104 OggUtil::Make_ogg_page(*this, op);
00105 return ogg_page_eos(&op);
00106 }
00107
00108 EXPORT_C TInt TOggPage::GranulePos() const
00109 {
00110 ogg_page op;
00111 OggUtil::Make_ogg_page(*this, op);
00112 return ogg_page_granulepos(&op);
00113 }
00114
00115 EXPORT_C TInt TOggPage::SerialNo() const
00116 {
00117 ogg_page op;
00118 OggUtil::Make_ogg_page(*this, op);
00119 return ogg_page_serialno(&op);
00120 }
00121
00122 EXPORT_C TInt TOggPage::PageNo() const
00123 {
00124 ogg_page op;
00125 OggUtil::Make_ogg_page(*this, op);
00126 return ogg_page_pageno(&op);
00127 }
00128
00129
00130
00131
00132 EXPORT_C TOggPacket::TOggPacket()
00133 : iData(NULL, 0), iBOS(EFalse), iEOS(EFalse), iGranulePos(0), iPacketNo(0)
00134 {
00135 }
00136 #ifndef SYMBIAN_CODEC_FLOAT_POINT
00137 EXPORT_C void TOggPacket::GetOggData(TPtr8& aDataStore)
00138 {
00139
00140 ogg_packet testpckt;
00141 testpckt.packet = reinterpret_cast<ogg_reference*>(const_cast<unsigned char*>(iData.Ptr()));
00142 testpckt.bytes = iData.Length();
00143
00144
00145 TInt begin = testpckt.packet->begin;
00146 TInt length = testpckt.packet->length;
00147
00148 ogg_buffer *buffer = testpckt.packet->buffer;
00149 ogg_reference *next = testpckt.packet->next;
00150
00151
00152 unsigned char *data = buffer->data;
00153
00154 TInt ptr_count = 0;
00155
00156
00157 for(TInt i = 0;i < length; i++)
00158 {
00159 aDataStore[i] = data[begin+i];
00160 }
00161
00162 ptr_count += length;
00163
00164
00165 while(next)
00166 {
00167
00168 testpckt.packet = next;
00169
00170
00171 begin = testpckt.packet->begin;
00172 length = testpckt.packet->length;
00173
00174 buffer = testpckt.packet->buffer;
00175 next = testpckt.packet->next;
00176
00177 data = buffer->data;
00178
00179
00180 for(TInt i = 0;i < length; i++)
00181 {
00182 aDataStore[i+ptr_count] = data[begin+i];
00183 }
00184
00185 ptr_count += length;
00186
00187 }
00188 }
00189 #endif