Shaka Player Embedded
av_media_track.mm
Go to the documentation of this file.
1 // Copyright 2020 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 
16 
17 #include <atomic>
18 
19 namespace shaka {
20 namespace media {
21 namespace ios {
22 
23 namespace {
24 
25 std::string GetId() {
26  static std::atomic_int g_id_{1};
27  const int id_ = g_id_.fetch_add(1, std::memory_order_relaxed);
28  return "AvMediaTrack " + std::to_string(id_);
29 }
30 
31 std::string MakeStr(NSString *str) {
32  return str ? [str UTF8String] : "";
33 }
34 
35 
36 } // namespace
37 
38 AvMediaTrack::AvMediaTrack(AVPlayerItem *item, AVMediaSelectionGroup *group,
39  AVMediaSelectionOption *option)
40  : MediaTrack(MediaTrackKind::Unknown, MakeStr(option.displayName),
41  MakeStr(option.extendedLanguageTag), GetId()),
42  item_(item),
43  group_(group),
44  option_(option) {}
45 
47 
48 bool AvMediaTrack::enabled() const {
49  return [item_.currentMediaSelection selectedMediaOptionInMediaSelectionGroup:group_] == option_;
50 }
51 
53  if (enabled) {
54  [item_ selectMediaOption:option_ inMediaSelectionGroup:group_];
55  } else if (this->enabled()) {
56  if (group_.allowsEmptySelection)
57  [item_ selectMediaOption:nil inMediaSelectionGroup:group_];
58  else
59  [item_ selectMediaOption:group_.defaultOption inMediaSelectionGroup:group_];
60  }
61 }
62 
63 } // namespace ios
64 } // namespace media
65 } // namespace shaka
bool enabled() const override
std::string to_string(VideoReadyState state)
Definition: media_player.cc:32
void SetEnabled(bool enabled) override
AvMediaTrack(AVPlayerItem *item, AVMediaSelectionGroup *group, AVMediaSelectionOption *option)