Go to the documentation of this file.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
00033
00034
00035
00036 #include <stdlib.h>
00037 #include <stdio.h>
00038 #include <string.h>
00039 #include <vector>
00040
00041 #include <boost/cstdint.hpp>
00042 #include <boost/thread.hpp>
00043 #include <boost/date_time/posix_time/posix_time.hpp>
00044 #include <boost/date_time/posix_time/posix_time_io.hpp>
00045
00046 #include "server_configuration.h"
00047
00048 #ifndef FFMPEG_WRAPPER_HEADER_INCLUDED
00049 #define FFMPEG_WRAPPER_HEADER_INCLUDED
00050
00051 #ifdef HAVE_AV_CONFIG_H
00052 #undef HAVE_AV_CONFIG_H
00053 #endif
00054
00055 #define CODER_BUF_SIZE 50000
00056
00057
00058 namespace ros_http_video_streamer
00059 {
00060
00061
00062 class AVCodec;
00063 class AVOutputFormat;
00064 class AVCodecContext;
00065 class AVFormatContext;
00066 class AVPicture;
00067 class AVStream;
00068 class AVFrame;
00069
00070
00071 class FFMPEG_Wrapper
00072 {
00073
00074 public:
00075
00076 FFMPEG_Wrapper();
00077 ~FFMPEG_Wrapper();
00078
00079
00080 int init(int input_width,
00081 int input_height,
00082 const ServerConfiguration& config);
00083
00084
00085 void shutdown();
00086
00087
00088 void encode_bgr_frame(uint8_t *bgr_data, std::vector<uint8_t>& encoded_frame);
00089
00090 void encode_rgb_frame(uint8_t *rgb_data, std::vector<uint8_t>& encoded_frame);
00091
00092
00093 void encode_mono8_frame(uint8_t *gray8_data, std::vector<uint8_t>& encoded_frame);
00094
00095 void encode_mono16_frame(uint8_t *gray16_data, std::vector<uint8_t>& encoded_frame);
00096
00097
00098 void get_header(std::vector<uint8_t>& header);
00099
00100 void get_trailer(std::vector<uint8_t>& trailer);
00101
00102 private:
00103
00104 template<int CODING_FORMAT>
00105 void encode_frame(uint8_t *image_data, std::vector<uint8_t>& encoded_frame);
00106
00107
00108
00109
00110 boost::mutex frame_mutex_;
00111 boost::mutex codec_mutex_;
00112
00113
00114 AVCodec *ffmpeg_codec_;
00115 AVOutputFormat *ffmpeg_output_format_;
00116 AVCodecContext *ffmpeg_codec_context_;
00117 AVFormatContext *ffmpeg_format_context_;
00118 AVPicture* ffmpeg_src_picture_;
00119 AVPicture* ffmpeg_dst_picture_;
00120 AVStream *ffmpeg_video_st_;
00121 AVFrame *ffmpeg_frame_;
00122 double ffmpeg_video_pts_;
00123 struct SwsContext *ffmpeg_sws_ctx_;
00124
00125
00126 ServerConfiguration config_;
00127
00128
00129 int input_width_;
00130 int input_height_;
00131 int output_width_;
00132 int output_height_;
00133
00134 boost::posix_time::ptime time_started_;
00135
00136 bool init_;
00137
00138 };
00139
00140 }
00141
00142 #endif
00143