Blame view

trunk/src/app/srs_app_encoder.hpp 3.2 KB
1 2 3
/*
The MIT License (MIT)
4
Copyright (c) 2013-2014 winlin
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23

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.
*/
24 25
#ifndef SRS_APP_ENCODER_HPP
#define SRS_APP_ENCODER_HPP
26 27

/*
28
#include <srs_app_encoder.hpp>
29 30 31 32
*/
#include <srs_core.hpp>

#include <string>
winlin authored
33
#include <vector>
34
35
#include <srs_app_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

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

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

#endif
114 115

#endif