正在显示
4 个修改的文件
包含
60 行增加
和
10 行删除
| @@ -8,7 +8,8 @@ _cur_a_ts_ms(INT64_MAX), | @@ -8,7 +8,8 @@ _cur_a_ts_ms(INT64_MAX), | ||
| 8 | _cur_v_ts_ms(INT64_MAX), | 8 | _cur_v_ts_ms(INT64_MAX), |
| 9 | _end_time_ms(0), | 9 | _end_time_ms(0), |
| 10 | _cur_a_frame(NULL), | 10 | _cur_a_frame(NULL), |
| 11 | -_cur_v_frame(NULL) | 11 | +_cur_v_frame(NULL), |
| 12 | +_media_role(mr_student) | ||
| 12 | { | 13 | { |
| 13 | } | 14 | } |
| 14 | 15 | ||
| @@ -19,6 +20,7 @@ CAVDecoder::~CAVDecoder() | @@ -19,6 +20,7 @@ CAVDecoder::~CAVDecoder() | ||
| 19 | 20 | ||
| 20 | int CAVDecoder::add(media_info &info) | 21 | int CAVDecoder::add(media_info &info) |
| 21 | { | 22 | { |
| 23 | + _media_role = info.m_role; | ||
| 22 | if (info.m_type == mt_audio) { | 24 | if (info.m_type == mt_audio) { |
| 23 | _a_start_time_ms = info.start_time_ms; | 25 | _a_start_time_ms = info.start_time_ms; |
| 24 | _a_end_time_ms = info.end_time_ms; | 26 | _a_end_time_ms = info.end_time_ms; |
| @@ -15,7 +15,10 @@ public: | @@ -15,7 +15,10 @@ public: | ||
| 15 | bool get_one_v_frame(); | 15 | bool get_one_v_frame(); |
| 16 | int64_t _cur_a_ts_ms; | 16 | int64_t _cur_a_ts_ms; |
| 17 | int64_t _cur_v_ts_ms; | 17 | int64_t _cur_v_ts_ms; |
| 18 | + media_role _media_role; | ||
| 18 | 19 | ||
| 20 | + AVFrame * _cur_a_frame; | ||
| 21 | + AVFrame * _cur_v_frame; | ||
| 19 | protected: | 22 | protected: |
| 20 | list<media_info> _video_info; | 23 | list<media_info> _video_info; |
| 21 | list<media_info> _audio_info; | 24 | list<media_info> _audio_info; |
| @@ -26,8 +29,7 @@ protected: | @@ -26,8 +29,7 @@ protected: | ||
| 26 | int64_t _v_start_time_ms; | 29 | int64_t _v_start_time_ms; |
| 27 | int64_t _v_end_time_ms; | 30 | int64_t _v_end_time_ms; |
| 28 | int64_t _end_time_ms; | 31 | int64_t _end_time_ms; |
| 29 | - AVFrame * _cur_a_frame; | ||
| 30 | - AVFrame * _cur_v_frame; | 32 | + |
| 31 | private: | 33 | private: |
| 32 | AVFrame * get_blank_frame(); | 34 | AVFrame * get_blank_frame(); |
| 33 | AVFrame * get_silence_frame(); | 35 | AVFrame * get_silence_frame(); |
| @@ -3,8 +3,16 @@ | @@ -3,8 +3,16 @@ | ||
| 3 | 3 | ||
| 4 | CAVTranscoder::CAVTranscoder(): | 4 | CAVTranscoder::CAVTranscoder(): |
| 5 | _start_time(INT64_MAX), | 5 | _start_time(INT64_MAX), |
| 6 | -_all_processed(true) | 6 | +_all_processed(true), |
| 7 | +_one2one(false), | ||
| 8 | +_nOutputWidth(320) | ||
| 7 | { | 9 | { |
| 10 | + if (_one2one) { | ||
| 11 | + _nOutputHeight = 480; | ||
| 12 | + } | ||
| 13 | + else { | ||
| 14 | + _nOutputHeight = 240; | ||
| 15 | + } | ||
| 8 | } | 16 | } |
| 9 | 17 | ||
| 10 | 18 | ||
| @@ -38,7 +46,7 @@ int CAVTranscoder::add(media_info & info) | @@ -38,7 +46,7 @@ int CAVTranscoder::add(media_info & info) | ||
| 38 | int64_t CAVTranscoder::transcode() | 46 | int64_t CAVTranscoder::transcode() |
| 39 | { | 47 | { |
| 40 | vector<CAVDecoder *> decoders_got_frame; | 48 | vector<CAVDecoder *> decoders_got_frame; |
| 41 | - vector < CAVDecoder *>::iterator it = _decoders.begin(); | 49 | + vector <CAVDecoder *>::iterator it = _decoders.begin(); |
| 42 | for (; it != _decoders.end();) { | 50 | for (; it != _decoders.end();) { |
| 43 | if((*it)->get_one_v_frame()){ | 51 | if((*it)->get_one_v_frame()){ |
| 44 | decoders_got_frame.push_back(*it); | 52 | decoders_got_frame.push_back(*it); |
| @@ -201,6 +209,16 @@ int CAVTranscoder::open_output_file(const char *filename) | @@ -201,6 +209,16 @@ int CAVTranscoder::open_output_file(const char *filename) | ||
| 201 | 209 | ||
| 202 | int CAVTranscoder::mix_and_output_vframe(vector<CAVDecoder *> & decoders_got_frame) | 210 | int CAVTranscoder::mix_and_output_vframe(vector<CAVDecoder *> & decoders_got_frame) |
| 203 | { | 211 | { |
| 212 | + if (_one2one){ | ||
| 213 | + return mix_and_output_one2one_vframe(decoders_got_frame); | ||
| 214 | + } | ||
| 215 | + else { | ||
| 216 | + return mix_and_output_one2many_vframe(decoders_got_frame); | ||
| 217 | + } | ||
| 218 | + } | ||
| 219 | + | ||
| 220 | + int CAVTranscoder::mix_and_output_aframe(vector<CAVDecoder *> & decoders_got_frame) | ||
| 221 | + { | ||
| 204 | vector < CAVDecoder *>::iterator it = decoders_got_frame.begin(); | 222 | vector < CAVDecoder *>::iterator it = decoders_got_frame.begin(); |
| 205 | for (; it != decoders_got_frame.end(); it++) { | 223 | for (; it != decoders_got_frame.end(); it++) { |
| 206 | (*it)->free_cur_a_frame(); | 224 | (*it)->free_cur_a_frame(); |
| @@ -208,16 +226,36 @@ int CAVTranscoder::open_output_file(const char *filename) | @@ -208,16 +226,36 @@ int CAVTranscoder::open_output_file(const char *filename) | ||
| 208 | return 0; | 226 | return 0; |
| 209 | } | 227 | } |
| 210 | 228 | ||
| 211 | - int CAVTranscoder::mix_and_output_aframe(vector<CAVDecoder *> & decoders_got_frame) | 229 | + int CAVTranscoder::mix_and_output_one2many_vframe(vector<CAVDecoder *> & decoders_got_frame) |
| 212 | { | 230 | { |
| 213 | - vector < CAVDecoder *>::iterator it = decoders_got_frame.begin(); | ||
| 214 | - for (; it != decoders_got_frame.end(); it++) { | ||
| 215 | - (*it)->free_cur_v_frame(); | 231 | + return 0; |
| 232 | + } | ||
| 233 | + | ||
| 234 | + int CAVTranscoder::fillDestFrame(AVFrame * pDstFrame, AVFrame * pSrcFrame, int x, int y) | ||
| 235 | + { | ||
| 236 | + | ||
| 237 | + } | ||
| 238 | + | ||
| 239 | + int CAVTranscoder::mix_and_output_one2one_vframe(vector<CAVDecoder *> & decoders_got_frame) | ||
| 240 | + { | ||
| 241 | + //prepare one2one base frame | ||
| 242 | + AVFrame *pDstFrame = av_frame_alloc(); | ||
| 243 | + int nDstSize = avpicture_get_size(AV_PIX_FMT_YUV420P,_nOutputWidth, _nOutputHeight); | ||
| 244 | + uint8_t *dstbuf = new uint8_t[nDstSize]; | ||
| 245 | + avpicture_fill((AVPicture*)pDstFrame, dstbuf, AV_PIX_FMT_YUV420P, _nOutputWidth, _nOutputHeight); | ||
| 246 | + if (decoders_got_frame.size() == 2){ | ||
| 247 | + fillDestFrame(pDstFrame, decoders_got_frame[0]->_cur_v_frame, 0, decoders_got_frame[0]->_media_role == mr_teacher ? 0 : 240); | ||
| 248 | + fillDestFrame(pDstFrame, decoders_got_frame[1]->_cur_v_frame, 0, decoders_got_frame[1]->_media_role == mr_teacher ? 0 : 240); | ||
| 249 | + } | ||
| 250 | + else { | ||
| 251 | + fillDestFrame(pDstFrame, decoders_got_frame[0]->_cur_v_frame, 0, 0); | ||
| 216 | } | 252 | } |
| 217 | return 0; | 253 | return 0; |
| 218 | } | 254 | } |
| 219 | 255 | ||
| 220 | - int encode_write_frame(AVFrame *filt_frame, unsigned int stream_index, int *got_frame) { | 256 | +int encode_write_frame(AVFrame *filt_frame, unsigned int stream_index, int *got_frame) { |
| 257 | + | ||
| 258 | + | ||
| 221 | int ret; | 259 | int ret; |
| 222 | int got_frame_local; | 260 | int got_frame_local; |
| 223 | AVPacket enc_pkt; | 261 | AVPacket enc_pkt; |
| @@ -23,9 +23,17 @@ protected: | @@ -23,9 +23,17 @@ protected: | ||
| 23 | int64_t _start_time; | 23 | int64_t _start_time; |
| 24 | int64_t _cur_a_time; | 24 | int64_t _cur_a_time; |
| 25 | int64_t _cur_v_time; | 25 | int64_t _cur_v_time; |
| 26 | + int _nOutputWidth; | ||
| 27 | + int _nOutputHeight; | ||
| 28 | + | ||
| 26 | private: | 29 | private: |
| 27 | int mix_and_output_vframe(vector<CAVDecoder *> & decoders_got_frame); | 30 | int mix_and_output_vframe(vector<CAVDecoder *> & decoders_got_frame); |
| 28 | int mix_and_output_aframe(vector<CAVDecoder *> & decoders_got_frame); | 31 | int mix_and_output_aframe(vector<CAVDecoder *> & decoders_got_frame); |
| 29 | bool _all_processed; | 32 | bool _all_processed; |
| 33 | + bool _one2one; | ||
| 34 | + int mix_and_output_one2one_vframe(vector<CAVDecoder *> & decoders_got_frame); | ||
| 35 | + int mix_and_output_one2many_vframe(vector<CAVDecoder *> & decoders_got_frame); | ||
| 36 | + | ||
| 37 | + int fillDestFrame(AVFrame * pDstFrame, AVFrame * pSrcFrame, int x, int y); | ||
| 30 | }; | 38 | }; |
| 31 | 39 |
-
请 注册 或 登录 后发表评论