AVTranscoder.h 1.8 KB
#pragma once
#include "AVDecoder.h"


class CAVTranscoder
{
public:
	CAVTranscoder(bool bOne2One);
	virtual ~CAVTranscoder();

	int add(media_info & info);
	int64_t transcode();
	bool all_processed();
	int close();
	int open_output_file(const char *filename);

protected:
	vector < CAVDecoder *> _decoders;

	AVFormatContext * _ofmt_ctx;
	int64_t _start_time;
	double _cur_a_time;
	int64_t _cur_v_time;
	int _nOutputWidth;
	int _nOutputHeight;
	int64_t _cur_out_v_ts;
	int64_t _cur_out_a_ts;

private:
	int mix_and_output_vframe(vector<CAVDecoder *> & decoders_got_frame);
	int mix_and_output_aframe(vector<CAVDecoder *> & decoders_got_frame);
	bool _all_processed;
	bool _one2one;
	int mix_and_output_one2one_vframe(vector<CAVDecoder *> & decoders_got_frame);
	int mix_and_output_one2many_vframe(vector<CAVDecoder *> & decoders_got_frame);

	int fillDestFrame(AVFrame * pDstFrame, AVFrame * pSrcFrame, int x, int y);
	int fillDestFrame(AVFrame * pDstFrame, AVFrame * pSrcFrame, int destx, int desty, int srcx,int srcy,int w,int h);
	int encode_write_frame(AVFrame *filt_frame, unsigned int stream_index, int *got_frame);
	int flush_encoder(unsigned int stream_index);

	int init_scale_context(struct SwsContext ** ctx, AVFrame ** frame, int src_w, int src_h, int dest_w, int dest_h);
	int free_scale_context(struct SwsContext ** ctx, AVFrame ** frame);

	void * _a_frame_pool;
	int _max_audio;
	struct SwsContext * _swsCtx_320_240;
	struct SwsContext * _swsCtx_240_320;
	struct SwsContext * _swsCtx_240_240;
	AVFrame * _scaledFrame_320_240;
	AVFrame * _scaledFrame_240_320;
	AVFrame * _scaledFrame_240_240;
	int _last_videos_got;
	AVFrame * _teacherFrame;
	AVFrame * _studentFrame; // for one2one,keep the last frame

	uint8_t _blank_y, _blank_u, _blank_v;
public:
	void set_max_audio(int max_audio);
};