Shaka Player Embedded
apple_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_APPLE_DECODER_H_
16 #define SHAKA_EMBEDDED_MEDIA_APPLE_DECODER_H_
17 
18 #include <AudioToolbox/AudioToolbox.h>
19 #include <VideoToolbox/VideoToolbox.h>
20 
21 #include <memory>
22 #include <string>
23 #include <type_traits>
24 #include <vector>
25 
26 #include "shaka/media/decoder.h"
27 #include "shaka/media/frames.h"
29 #include "src/debug/mutex.h"
31 #include "src/util/cfref.h"
32 
33 namespace shaka {
34 namespace media {
35 namespace apple {
36 
41 class AppleDecoder : public Decoder {
42  public:
43  AppleDecoder();
44  ~AppleDecoder() override;
45 
47  const MediaDecodingConfiguration& config) const override;
48 
49  void ResetDecoder() override;
50 
52  std::shared_ptr<EncodedFrame> input, const eme::Implementation* eme,
53  std::vector<std::shared_ptr<DecodedFrame>>* frames,
54  std::string* extra_info) override;
55 
56  private:
57  static void OnNewVideoFrame(void* user, void* frameUser, OSStatus status,
58  VTDecodeInfoFlags flags, CVImageBufferRef buffer,
59  CMTime pts, CMTime duration);
60  static OSStatus AudioInputCallback(
61  AudioConverterRef conv, UInt32* num_packets, AudioBufferList* data,
62  AudioStreamPacketDescription** desc, void* user);
63 
64  void ResetInternal();
65 
66  bool DecodeVideo(const uint8_t* data, size_t data_size,
67  std::string* extra_info);
68  bool DecodeAudio(const uint8_t* data, size_t data_size,
69  std::string* extra_info);
70 
71  bool InitVideoDecoder(std::shared_ptr<const StreamInfo> info,
72  std::string* extra_info);
73  bool InitAudioDecoder(std::shared_ptr<const StreamInfo> info,
74  std::string* extra_info);
75 
76  Mutex mutex_;
77  EncodedFrame* input_;
78  const uint8_t* input_data_;
79  size_t input_data_size_;
80  std::vector<std::shared_ptr<DecodedFrame>>* output_;
81  std::shared_ptr<const StreamInfo> decoder_stream_info_;
82 
83  util::CFRef<VTDecompressionSessionRef> vt_session_;
84  util::CFRef<CMVideoFormatDescriptionRef> format_desc_;
85 
87  OSStatus(*)(AudioConverterRef)>
88  at_session_;
89  AudioStreamPacketDescription audio_desc_;
90 };
91 
92 } // namespace apple
93 } // namespace media
94 } // namespace shaka
95 
96 #endif // SHAKA_EMBEDDED_MEDIA_APPLE_DECODER_H_
ExceptionCode type
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
MediaCapabilitiesInfo DecodingInfo(const MediaDecodingConfiguration &config) const override