summaryrefslogtreecommitdiffstats
path: root/media/filters/bitstream_converter.h
blob: 4f6a0d7f59dab2aa924c3d947975ea17858332c5 (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
79
80
81
// 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() {}

  // Attemps to convert the AVPacket from one format to another, based on the
  // specific type of BitstreamConverter that was instantiated.
  virtual bool Initialize() = 0;
  virtual bool ConvertPacket(AVPacket* packet) = 0;

 private:
  DISALLOW_COPY_AND_ASSIGN(BitstreamConverter);
};

class IdentityBitstreamConverter : public BitstreamConverter {
 public:
  IdentityBitstreamConverter() {}
  virtual ~IdentityBitstreamConverter() {}

  virtual bool Initialize() { return true; }
  virtual bool ConvertPacket(AVPacket* packet) { return true; }

 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_