WaveDecoder.cpp (1888B)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim:set ts=2 sw=2 sts=2 et cindent: */ 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 "WaveDecoder.h" 8 9 #include "MediaContainerType.h" 10 #include "MediaDecoder.h" 11 12 namespace mozilla { 13 14 /* static */ 15 bool WaveDecoder::IsSupportedType(const MediaContainerType& aContainerType) { 16 if (!MediaDecoder::IsWaveEnabled()) { 17 return false; 18 } 19 if (aContainerType.Type() == MEDIAMIMETYPE("audio/wave") || 20 aContainerType.Type() == MEDIAMIMETYPE("audio/x-wav") || 21 aContainerType.Type() == MEDIAMIMETYPE("audio/wav") || 22 aContainerType.Type() == MEDIAMIMETYPE("audio/x-pn-wav")) { 23 return (aContainerType.ExtendedType().Codecs().IsEmpty() || 24 aContainerType.ExtendedType().Codecs() == "1" || 25 aContainerType.ExtendedType().Codecs() == "3" || 26 aContainerType.ExtendedType().Codecs() == "6" || 27 aContainerType.ExtendedType().Codecs() == "7"); 28 } 29 30 return false; 31 } 32 33 /* static */ 34 nsTArray<UniquePtr<TrackInfo>> WaveDecoder::GetTracksInfo( 35 const MediaContainerType& aType) { 36 nsTArray<UniquePtr<TrackInfo>> tracks; 37 if (!IsSupportedType(aType)) { 38 return tracks; 39 } 40 41 const MediaCodecs& codecs = aType.ExtendedType().Codecs(); 42 if (codecs.IsEmpty()) { 43 tracks.AppendElement( 44 CreateTrackInfoWithMIMETypeAndContainerTypeExtraParameters( 45 "audio/x-wav"_ns, aType)); 46 return tracks; 47 } 48 49 for (const auto& codec : codecs.Range()) { 50 tracks.AppendElement( 51 CreateTrackInfoWithMIMETypeAndContainerTypeExtraParameters( 52 "audio/wave; codecs="_ns + NS_ConvertUTF16toUTF8(codec), aType)); 53 } 54 return tracks; 55 } 56 57 } // namespace mozilla