Blame view

trunk/src/core/srs_core_encoder.hpp 2.8 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
/*
The MIT License (MIT)

Copyright (c) 2013 winlin

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#ifndef SRS_CORE_ENCODER_HPP
#define SRS_CORE_ENCODER_HPP

/*
#include <srs_core_encoder.hpp>
*/
#include <srs_core.hpp>

#include <string>
winlin authored
33
#include <vector>
34
35
#include <srs_core_thread.hpp>
winlin authored
36
winlin authored
37
class SrsConfDirective;
38
class SrsRequest;
winlin authored
39
class SrsPithyPrint;
40 41

#ifdef SRS_FFMPEG
winlin authored
42 43 44 45 46 47 48 49 50

/**
* a transcode engine: ffmepg,
* used to transcode a stream to another.
*/
class SrsFFMPEG
{
private:
	bool started;
winlin authored
51
	pid_t pid;
winlin authored
52
private:
winlin authored
53 54 55
	std::string log_file;
	int log_fd;
private:
winlin authored
56
	std::string 				ffmpeg;
winlin authored
57
	std::vector<std::string> 	vfilter;
winlin authored
58 59 60 61 62 63 64 65
	std::string 				vcodec;
	int 						vbitrate;
	double 						vfps;
	int 						vwidth;
	int 						vheight;
	int 						vthreads;
	std::string 				vprofile;
	std::string 				vpreset;
winlin authored
66
	std::vector<std::string> 	vparams;
winlin authored
67 68 69 70
	std::string 				acodec;
	int 						abitrate;
	int 						asample_rate;
	int 						achannels;
winlin authored
71
	std::vector<std::string> 	aparams;
winlin authored
72
	std::string 				output;
winlin authored
73
	std::string 				input;
winlin authored
74 75 76 77
public:
	SrsFFMPEG(std::string ffmpeg_bin);
	virtual ~SrsFFMPEG();
public:
78
	virtual int initialize(SrsRequest* req, SrsConfDirective* engine);
winlin authored
79
	virtual int start();
winlin authored
80
	virtual int cycle();
winlin authored
81 82 83 84 85 86 87
	virtual void stop();
};

/**
* the encoder for a stream,
* may use multiple ffmpegs to transcode the specified stream.
*/
88
class SrsEncoder : public ISrsThreadHandler
89
{
winlin authored
90
private:
winlin authored
91 92
	std::vector<SrsFFMPEG*> ffmpegs;
private:
93 94
	SrsThread* pthread;
	SrsPithyPrint* pithy_print;
95 96 97 98
public:
	SrsEncoder();
	virtual ~SrsEncoder();
public:
99
	virtual int on_publish(SrsRequest* req);
100
	virtual void on_unpublish();
101 102 103 104
// interface ISrsThreadHandler.
public:
	virtual int cycle();
	virtual void on_leave_loop();
winlin authored
105
private:
106
	virtual void clear_engines();
winlin authored
107
	virtual SrsFFMPEG* at(int index);
108
	virtual int parse_scope_engines(SrsRequest* req);
109
	virtual int parse_transcode(SrsRequest* req, SrsConfDirective* conf);
110
	virtual void encoder();
111 112 113
};

#endif
114 115

#endif