37 #include <theora_image_transport/Packet.h> 39 #include <theora/codec.h> 40 #include <theora/theoraenc.h> 41 #include <theora/theoradec.h> 46 #include <boost/scoped_array.hpp> 54 : fout_(filename,
std::ios::out|
std::ios::binary)
56 if (ogg_stream_init(&stream_state_, 0) == -1) {
57 ROS_FATAL(
"Unable to initialize ogg_stream_state structure");
67 if (ogg_stream_flush(&stream_state_, &page) != 0)
70 ogg_stream_clear(&stream_state_);
81 void msgToOggPacket(
const theora_image_transport::Packet &msg, ogg_packet &oggpacket)
83 oggpacket.bytes = msg.data.size();
84 oggpacket.b_o_s = msg.b_o_s;
85 oggpacket.e_o_s = msg.e_o_s;
86 oggpacket.granulepos = msg.granulepos;
87 oggpacket.packetno = msg.packetno;
88 oggpacket.packet =
new unsigned char[oggpacket.bytes];
89 memcpy(oggpacket.packet, &msg.data[0], oggpacket.bytes);
94 fout_.write((
char*)page.header, page.header_len);
95 fout_.write((
char*)page.body, page.body_len);
98 void processMsg(
const theora_image_transport::PacketConstPtr& message)
105 ogg_packet oggpacket;
106 msgToOggPacket(*message, oggpacket);
107 boost::scoped_array<unsigned char> packet_guard(oggpacket.packet);
109 if (ogg_stream_packetin(&stream_state_, &oggpacket)) {
110 ROS_ERROR(
"Error while adding packet to stream.");
115 if (ogg_stream_pageout(&stream_state_, &page) != 0)
120 int main(
int argc,
char** argv)
127 cerr <<
"Usage: " << argv[0] <<
" stream:=/theora/image/stream outputFile" << endl;
131 ROS_WARN(
"ogg_saver: stream has not been remapped! Typical command-line usage:\n" 132 "\t$ ./ogg_saver stream:=<theora stream topic> outputFile");
ogg_stream_state stream_state_
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
int main(int argc, char **argv)
OggSaver(const char *filename)
ROSCPP_DECL void spin(Spinner &spinner)
void msgToOggPacket(const theora_image_transport::Packet &msg, ogg_packet &oggpacket)
ROSCPP_DECL std::string remap(const std::string &name)
void processMsg(const theora_image_transport::PacketConstPtr &message)
void writePage(ogg_page &page)