3rdparty/licenseReport: Add seperate LGPL checks
[haiku.git] / src / add-ons / media / plugins / ffmpeg / AVCodecEncoder.h
blob40cc42c8081b3b1d095173f83b1160d2c793c62f
1 /*
2 * Copyright 2009, Stephan Aßmus <superstippi@gmx.de>.
3 * All rights reserved. Distributed under the terms of the MIT license.
4 */
5 #ifndef AVCODEC_ENCODER_H
6 #define AVCODEC_ENCODER_H
9 #include <MediaFormats.h>
11 extern "C" {
12 #include "avcodec.h"
13 #include "swscale.h"
14 #include "libavutil/fifo.h"
17 #include "EncoderPlugin.h"
20 #if LIBAVCODEC_VERSION_INT > ((54 << 16) | (50 << 8))
21 typedef AVCodecID CodecID;
22 #endif
25 class AVCodecEncoder : public Encoder {
26 public:
27 AVCodecEncoder(uint32 codecID,
28 int bitRateScale);
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
48 // codec buffer size.
50 private:
51 void _Init();
52 status_t _Setup();
54 bool _OpenCodecIfNeeded();
55 void _CloseCodecIfNeeded();
57 status_t _EncodeAudio(const void* buffer,
58 int64 frameCount,
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,
65 int64 frameCount,
66 media_encode_info* info);
68 private:
69 media_format fInputFormat;
70 encode_parameters fEncodeParameters;
71 int fBitRateScale;
73 // FFmpeg related members
74 // TODO: Refactor common base class from AVCodec[De|En]Coder!
75 CodecID fCodecID;
76 AVCodec* fCodec;
77 AVCodecContext* fOwnContext;
78 AVCodecContext* fContext;
80 enum {
81 CODEC_INIT_NEEDED = 0,
82 CODEC_INIT_DONE,
83 CODEC_INIT_FAILED
85 uint32 fCodecInitStatus;
87 // For video (color space conversion):
88 AVPicture fSrcFrame;
89 AVPicture fDstFrame;
90 AVFrame* fFrame;
91 SwsContext* fSwsContext;
93 // For encoded audio:
94 AVFifoBuffer* fAudioFifo;
96 int64 fFramesWritten;
98 uint8* fChunkBuffer;
101 #endif // AVCODEC_ENCODER_H