2 * Copyright 2009, Stephan Aßmus <superstippi@gmx.de>.
3 * All rights reserved. Distributed under the terms of the MIT license.
5 #ifndef AVCODEC_ENCODER_H
6 #define AVCODEC_ENCODER_H
9 #include <MediaFormats.h>
14 #include "libavutil/fifo.h"
17 #include "EncoderPlugin.h"
20 #if LIBAVCODEC_VERSION_INT > ((54 << 16) | (50 << 8))
21 typedef AVCodecID CodecID
;
25 class AVCodecEncoder
: public Encoder
{
27 AVCodecEncoder(uint32 codecID
,
30 virtual ~AVCodecEncoder();
32 virtual status_t
AcceptedFormat(
33 const media_format
* proposedInputFormat
,
34 media_format
* _acceptedInputFormat
= NULL
);
36 virtual status_t
SetUp(const media_format
* inputFormat
);
38 virtual status_t
GetEncodeParameters(
39 encode_parameters
* parameters
) const;
40 virtual status_t
SetEncodeParameters(
41 encode_parameters
* parameters
);
43 virtual status_t
Encode(const void* buffer
, int64 frameCount
,
44 media_encode_info
* info
);
46 // TODO: Turns out we need Flush() after all. We buffer encoded audio
47 // in a FIFO, since the user suggested buffer size may not fit the
54 bool _OpenCodecIfNeeded();
55 void _CloseCodecIfNeeded();
57 status_t
_EncodeAudio(const void* buffer
,
59 media_encode_info
* info
);
60 status_t
_EncodeAudio(const uint8
* buffer
,
61 size_t bufferSize
, int64 frameCount
,
62 media_encode_info
* info
);
64 status_t
_EncodeVideo(const void* buffer
,
66 media_encode_info
* info
);
69 media_format fInputFormat
;
70 encode_parameters fEncodeParameters
;
73 // FFmpeg related members
74 // TODO: Refactor common base class from AVCodec[De|En]Coder!
77 AVCodecContext
* fOwnContext
;
78 AVCodecContext
* fContext
;
81 CODEC_INIT_NEEDED
= 0,
85 uint32 fCodecInitStatus
;
87 // For video (color space conversion):
91 SwsContext
* fSwsContext
;
94 AVFifoBuffer
* fAudioFifo
;
101 #endif // AVCODEC_ENCODER_H