tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

MediaCapabilitiesValidation.h (2522B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=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 https://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef DOM_MEDIA_MEDIACAPABILITIES_MEDIACAPABILITIESVALIDATION_H_
      8 #define DOM_MEDIA_MEDIACAPABILITIES_MEDIACAPABILITIESVALIDATION_H_
      9 #include "mozilla/DefineEnum.h"
     10 #include "mozilla/Result.h"
     11 #include "mozilla/Variant.h"
     12 // Media Capabilities API spec validation check functions.
     13 // These functions are used as a first pass to filter out non-compliant
     14 // configurations according to the spec. Lower-level SW/HW compability checks
     15 // are handled in MediaCapabilities.cpp.
     16 //
     17 // See also:
     18 // https://github.com/w3c/media-capabilities
     19 // commit: b9d2f30c00c534ac44179f546bc60f421ce78070
     20 namespace mozilla {
     21 class ErrorResult;
     22 
     23 namespace dom {
     24 class Promise;
     25 struct MediaDecodingConfiguration;
     26 struct MediaEncodingConfiguration;
     27 enum class MediaEncodingType : uint8_t;
     28 enum class MediaDecodingType : uint8_t;
     29 }  // namespace dom
     30 
     31 namespace mediacaps {
     32 enum class AVType { AUDIO, VIDEO };
     33 MOZ_DEFINE_ENUM_CLASS_WITH_TOSTRING(
     34    ValidationError,
     35    (MissingType, InvalidAudioConfiguration, InvalidVideoConfiguration,
     36     InvalidMIMEType, InvalidAudioType, InvalidVideoType, SingleCodecHasParams,
     37     ContainerMissingCodecsParam, ContainerCodecsNotSingle, FramerateInvalid,
     38     InapplicableMember, KeySystemWrongType, KeySystemAudioMissing,
     39     KeySystemVideoMissing, SENTINEL));
     40 
     41 // Variant to consolidate encoding/decoding checks into the same functions
     42 using MediaType = Variant<dom::MediaEncodingType, dom::MediaDecodingType>;
     43 using ValidationResult = mozilla::Result<mozilla::Ok, ValidationError>;
     44 
     45 // https://w3c.github.io/media-capabilities/#mediaconfiguration
     46 ValidationResult IsValidMediaDecodingConfiguration(
     47    const dom::MediaDecodingConfiguration& aConfig);
     48 
     49 // NOTE: No formal validation steps in the spec.
     50 //       Currently just calls IsValidMediaConfiguration.
     51 ValidationResult IsValidMediaEncodingConfiguration(
     52    const dom::MediaEncodingConfiguration& aConfig);
     53 
     54 // Helpers which also convert the validation error to text
     55 void RejectWithValidationResult(dom::Promise* aPromise,
     56                                const ValidationError aErr);
     57 void ThrowWithValidationResult(ErrorResult& aRv, const ValidationError aErr);
     58 }  // namespace mediacaps
     59 }  // namespace mozilla
     60 
     61 #endif