summaryrefslogtreecommitdiff
path: root/liboutput/encode.h
blob: db7f122420dfc5e342f33d90199240411adcdff7 (plain)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
 * Image plugin to VDR (C++)
 *
 * (C) 2004-2011 Andreas Brachold    <vdr07 at deltab.de>
 *  Created: Thu Aug  5 2004
 *
 * This code is distributed under the terms and conditions of the
 * GNU GENERAL PUBLIC LICENSE. See the file COPYING for details.
 *
 */
 
#ifndef _ENCODE_H
#define _ENCODE_H

extern "C" {
#include <libavcodec/avcodec.h>
}

#include "../setup-image.h"
//#define TESTCODE

class cEncode
{
    static AVCodec *m_pavCodec;
    unsigned int m_nMaxMPEGSize;
    uint8_t *m_pImageFilled; 
    uint8_t *m_pImageYUV;

protected:
    const unsigned int m_nNumberOfFramesToEncode;
    uint8_t *m_pMPEG; 
    uint8_t *m_pImageRGB;
    bool m_bUsePAL;
    unsigned int m_nMPEGSize;
    unsigned int m_nWidth;
    unsigned int m_nHeight;
    unsigned int *m_pFrameSizes;

public:
    cEncode(unsigned int nNumberOfFramesToEncode);
    virtual ~cEncode();

    /*Load Shared Library and Register Codec*/
    static bool Register();
    /*UnLoad Shared*/
    static void UnRegister();

    bool Encode();
    inline const uint8_t *Data() const       { return m_pMPEG; }
    inline unsigned int Size() const         { return m_nMPEGSize; }
    inline unsigned int GetFrames() const    { return m_nNumberOfFramesToEncode; } 
    inline unsigned int GetFrameRate() const { return m_bUsePAL?25:30; } 

    inline unsigned int GetFrameSize(unsigned int nframeNumber) const 
      { return *(m_pFrameSizes + nframeNumber); } 

    inline unsigned int GetHeight() const       { return m_nHeight; } 
    inline unsigned int GetWidth() const        { return m_nWidth;  } 
    inline unsigned int GetBorderHeight() const { return ImageSetup.m_nBorderHeight; } 
    inline unsigned int GetBorderWidth() const  { return ImageSetup.m_nBorderWidth; } 

    inline uint8_t *GetRGBMem() { return m_pImageRGB; }
    void  ClearRGBMem ();

#ifdef TESTCODE
    bool Load(const char* szFileName);
    bool Save(const char* szFileName) const;
#endif

private:
    void AllocateBuffers();
    void ReleaseBuffers();
    void SetupEncodingParameters(AVCodecContext *context);
    bool ConvertImageToFrame(AVFrame *frame);
    bool EncodeFrames(AVCodecContext *context, AVFrame *frame);
};

#endif /* _ENCODE_H */