Shaka Player Embedded
ffmpeg_decoder.h
Go to the documentation of this file.
1 // Copyright 2019 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef SHAKA_EMBEDDED_MEDIA_FFMPEG_FFMPEG_DECODER_H_
16 #define SHAKA_EMBEDDED_MEDIA_FFMPEG_FFMPEG_DECODER_H_
17 
18 extern "C" {
19 #include <libavcodec/avcodec.h>
20 #include <libavformat/avformat.h>
21 }
22 
23 #include <memory>
24 #include <string>
25 #include <vector>
26 
27 #include "shaka/media/decoder.h"
28 #include "shaka/media/frames.h"
30 #include "src/debug/mutex.h"
31 
32 namespace shaka {
33 namespace media {
34 namespace ffmpeg {
35 
40 class FFmpegDecoder : public Decoder {
41  public:
42  FFmpegDecoder();
43  ~FFmpegDecoder() override;
44 
46  const MediaDecodingConfiguration& config) const override;
47 
48  void ResetDecoder() override;
49 
51  std::shared_ptr<EncodedFrame> input, const eme::Implementation* eme,
52  std::vector<std::shared_ptr<DecodedFrame>>* frames,
53  std::string* extra_info) override;
54 
55  private:
56 #ifdef ENABLE_HARDWARE_DECODE
57  static AVPixelFormat GetPixelFormat(AVCodecContext* ctx,
58  const AVPixelFormat* formats);
59 #endif
60 
61  bool InitializeDecoder(std::shared_ptr<const StreamInfo> info,
62  bool allow_hardware,
63  std::string* extra_info);
64  bool ReadFromDecoder(std::shared_ptr<const StreamInfo> stream_info,
65  std::shared_ptr<EncodedFrame> input,
66  std::vector<std::shared_ptr<DecodedFrame>>* decoded,
67  std::string* extra_info);
68 
69  Mutex mutex_;
70  const std::string codec_;
71 
72  AVCodecContext* decoder_ctx_;
73  AVFrame* received_frame_;
74 #ifdef ENABLE_HARDWARE_DECODE
75  AVBufferRef* hw_device_ctx_;
76  AVPixelFormat hw_pix_fmt_;
77 #endif
78  double prev_timestamp_offset_;
79  // The stream the decoder is currently configured to use.
80  std::shared_ptr<const StreamInfo> decoder_stream_info_;
81 };
82 
83 } // namespace ffmpeg
84 } // namespace media
85 } // namespace shaka
86 
87 #endif // SHAKA_EMBEDDED_MEDIA_FFMPEG_FFMPEG_DECODER_H_
MediaCapabilitiesInfo DecodingInfo(const MediaDecodingConfiguration &config) const override
std::list< std::shared_ptr< BaseFrame > > frames
Definition: streams.cc:128
MediaStatus Decode(std::shared_ptr< EncodedFrame > input, const eme::Implementation *eme, std::vector< std::shared_ptr< DecodedFrame >> *frames, std::string *extra_info) override