1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #include "FlacDecoder.h"
8 #include "MediaContainerType.h"
9 #include "mozilla/StaticPrefs_media.h"
10 #include "PDMFactory.h"
11 
12 namespace mozilla {
13 
14 /* static */
IsEnabled()15 bool FlacDecoder::IsEnabled() {
16 #ifdef MOZ_FFVPX
17   return StaticPrefs::media_flac_enabled();
18 #elif defined(MOZ_FFMPEG)
19   RefPtr<PDMFactory> platform = new PDMFactory();
20   return StaticPrefs::media_flac_enabled() &&
21          platform->SupportsMimeType("audio/flac"_ns);
22 #else
23   return false;
24 #endif
25 }
26 
27 /* static */
IsSupportedType(const MediaContainerType & aContainerType)28 bool FlacDecoder::IsSupportedType(const MediaContainerType& aContainerType) {
29   return IsEnabled() &&
30          (aContainerType.Type() == MEDIAMIMETYPE("audio/flac") ||
31           aContainerType.Type() == MEDIAMIMETYPE("audio/x-flac") ||
32           aContainerType.Type() == MEDIAMIMETYPE("application/x-flac"));
33 }
34 
35 /* static */
GetTracksInfo(const MediaContainerType & aType)36 nsTArray<UniquePtr<TrackInfo>> FlacDecoder::GetTracksInfo(
37     const MediaContainerType& aType) {
38   nsTArray<UniquePtr<TrackInfo>> tracks;
39   if (!IsSupportedType(aType)) {
40     return tracks;
41   }
42 
43   tracks.AppendElement(
44       CreateTrackInfoWithMIMETypeAndContainerTypeExtraParameters(
45           "audio/flac"_ns, aType));
46 
47   return tracks;
48 }
49 
50 }  // namespace mozilla
51