OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MEDIA_BASE_MEDIA_TRACKS_H_ | 5 #ifndef MEDIA_BASE_MAC_VIDEOTOOLBOX_HELPERS_H_ |
6 #define MEDIA_BASE_MEDIA_TRACKS_H_ | 6 #define MEDIA_BASE_MAC_VIDEOTOOLBOX_HELPERS_H_ |
7 | 7 |
8 #include <map> | 8 #include "base/mac/scoped_cftyperef.h" |
9 #include <string> | 9 #include "media/base/mac/videotoolbox_glue.h" |
10 #include <vector> | |
11 | |
12 #include "base/macros.h" | |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "media/base/media_export.h" | 10 #include "media/base/media_export.h" |
15 #include "media/base/media_track.h" | |
16 | 11 |
17 namespace media { | 12 namespace media { |
18 | 13 |
19 class AudioDecoderConfig; | 14 namespace video_toolbox { |
20 class VideoDecoderConfig; | |
21 | 15 |
22 class MEDIA_EXPORT MediaTracks { | 16 // Create a CFDictionaryRef with the given keys and values. |
| 17 MEDIA_EXPORT base::ScopedCFTypeRef<CFDictionaryRef> |
| 18 DictionaryWithKeysAndValues(CFTypeRef* keys, CFTypeRef* values, size_t size); |
| 19 |
| 20 // Create a CFDictionaryRef with the given key and value. |
| 21 MEDIA_EXPORT base::ScopedCFTypeRef<CFDictionaryRef> DictionaryWithKeyValue( |
| 22 CFTypeRef key, |
| 23 CFTypeRef value); |
| 24 |
| 25 // Create a CFArrayRef with the given array of integers. |
| 26 MEDIA_EXPORT base::ScopedCFTypeRef<CFArrayRef> ArrayWithIntegers(const int* v, |
| 27 size_t size); |
| 28 |
| 29 // Create a CFArrayRef with the given int and float values. |
| 30 MEDIA_EXPORT base::ScopedCFTypeRef<CFArrayRef> ArrayWithIntegerAndFloat( |
| 31 int int_val, |
| 32 float float_val); |
| 33 |
| 34 // Copy a H.264 frame stored in a CM sample buffer to an Annex B buffer. Copies |
| 35 // parameter sets for keyframes before the frame data as well. |
| 36 MEDIA_EXPORT bool CopySampleBufferToAnnexBBuffer( |
| 37 CoreMediaGlue::CMSampleBufferRef sbuf, |
| 38 bool keyframe, |
| 39 std::string* annexb_buffer); |
| 40 MEDIA_EXPORT bool CopySampleBufferToAnnexBBuffer( |
| 41 CoreMediaGlue::CMSampleBufferRef sbuf, |
| 42 bool keyframe, |
| 43 size_t annexb_buffer_size, |
| 44 char* annexb_buffer, |
| 45 size_t* used_buffer_size); |
| 46 |
| 47 // Helper class to add session properties to a VTCompressionSessionRef. |
| 48 class MEDIA_EXPORT SessionPropertySetter { |
23 public: | 49 public: |
24 typedef std::vector<scoped_ptr<MediaTrack>> MediaTracksCollection; | 50 SessionPropertySetter( |
| 51 base::ScopedCFTypeRef<VideoToolboxGlue::VTCompressionSessionRef> session, |
| 52 const VideoToolboxGlue* const glue); |
| 53 ~SessionPropertySetter(); |
25 | 54 |
26 MediaTracks(); | 55 bool Set(CFStringRef key, int32_t value); |
27 ~MediaTracks(); | 56 bool Set(CFStringRef key, bool value); |
28 | 57 bool Set(CFStringRef key, CFStringRef value); |
29 // Callers need to ensure that track id is unique. | 58 bool Set(CFStringRef key, CFArrayRef value); |
30 void AddAudioTrack(const AudioDecoderConfig& config, | |
31 const std::string& id, | |
32 const std::string& kind, | |
33 const std::string& label, | |
34 const std::string& language); | |
35 // Callers need to ensure that track id is unique. | |
36 void AddVideoTrack(const VideoDecoderConfig& config, | |
37 const std::string& id, | |
38 const std::string& kind, | |
39 const std::string& label, | |
40 const std::string& language); | |
41 | |
42 const MediaTracksCollection& tracks() const { return tracks_; } | |
43 | |
44 const AudioDecoderConfig& getAudioConfig(const std::string& id) const; | |
45 const VideoDecoderConfig& getVideoConfig(const std::string& id) const; | |
46 | |
47 // TODO(servolk): These are temporary helpers useful until all code paths are | |
48 // converted to properly handle multiple media tracks. | |
49 const AudioDecoderConfig& getFirstAudioConfig() const; | |
50 const VideoDecoderConfig& getFirstVideoConfig() const; | |
51 | 59 |
52 private: | 60 private: |
53 MediaTracksCollection tracks_; | 61 base::ScopedCFTypeRef<VideoToolboxGlue::VTCompressionSessionRef> session_; |
54 std::map<std::string, AudioDecoderConfig> audio_configs_; | 62 const VideoToolboxGlue* glue_; |
55 std::map<std::string, VideoDecoderConfig> video_configs_; | 63 }; |
56 | 64 |
57 DISALLOW_COPY_AND_ASSIGN(MediaTracks); | 65 } // namespace video_toolbox |
58 }; | |
59 | 66 |
60 } // namespace media | 67 } // namespace media |
61 | 68 |
62 #endif // MEDIA_BASE_MEDIA_TRACKS_H_ | 69 #endif // MEDIA_BASE_MAC_VIDEOTOOLBOX_HELPERS_H_ |
OLD | NEW |