forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbitstream_converter.h
86 lines (66 loc) · 2.72 KB
/
bitstream_converter.h
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
79
80
81
82
83
84
85
86
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Interface and some concrete classes for applying various transforms
// to AVPackets. FFmpegBitstreamConverter, in particular, can be used
// to apply FFmpeg bitstream filters to the incoming AVPacket to transcode
// the packet format.
#ifndef MEDIA_FILTERS_BITSTREAM_CONVERTER_H_
#define MEDIA_FILTERS_BITSTREAM_CONVERTER_H_
#include <string>
#include "base/basictypes.h"
#include "base/gtest_prod_util.h"
// FFmpeg types.
struct AVBitStreamFilterContext;
struct AVCodecContext;
struct AVPacket;
namespace media {
class BitstreamConverter {
public:
BitstreamConverter() {}
virtual ~BitstreamConverter() {}
// Initialize does any preparations needed before doing the actual
// conversion.
virtual bool Initialize() = 0;
// Attemps to convert the AVPacket from one format to another, based on the
// specific type of BitstreamConverter that was instantiated. Output will be
// stored into the |packet|, but user should be aware that conversion can free
// and reallocate the input buffer, if it needs to do so to fit it in.
virtual bool ConvertPacket(AVPacket* packet) = 0;
private:
DISALLOW_COPY_AND_ASSIGN(BitstreamConverter);
};
class IdentityBitstreamConverter : public BitstreamConverter {
public:
IdentityBitstreamConverter() {}
virtual ~IdentityBitstreamConverter() {}
virtual bool Initialize();
virtual bool ConvertPacket(AVPacket* packet);
private:
DISALLOW_COPY_AND_ASSIGN(IdentityBitstreamConverter);
};
class FFmpegBitstreamConverter : public BitstreamConverter {
public:
// Creates FFmpegBitstreamConverter based on the FFmpeg bistream filter
// corresponding to |filter_name|.
//
// The |stream_context| will be used during conversion and should be the
// AVCodecContext for the stream sourcing these packets. A reference to
// |stream_context| is retained, so it must outlive this class.
FFmpegBitstreamConverter(const std::string& filter_name,
AVCodecContext* stream_context);
virtual ~FFmpegBitstreamConverter();
virtual bool Initialize();
virtual bool ConvertPacket(AVPacket* packet);
private:
FRIEND_TEST_ALL_PREFIXES(BitstreamConverterTest, ConvertPacket_FailedFilter);
FRIEND_TEST_ALL_PREFIXES(BitstreamConverterTest, ConvertPacket_Success);
FRIEND_TEST_ALL_PREFIXES(BitstreamConverterTest,
ConvertPacket_SuccessInPlace);
std::string filter_name_;
AVBitStreamFilterContext* stream_filter_;
AVCodecContext* stream_context_;
DISALLOW_COPY_AND_ASSIGN(FFmpegBitstreamConverter);
};
} // namespace media
#endif // MEDIA_FILTERS_BITSTREAM_CONVERTER_H_