-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: create utils-format to reuse code between formats
- Loading branch information
Showing
9 changed files
with
140 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[package] | ||
name = "symphonia-utils-format" | ||
version = "0.5.4" | ||
description = "Project Symphonia utilities for formats." | ||
homepage = "https://github.com/pdeljanov/Symphonia" | ||
repository = "https://github.com/pdeljanov/Symphonia" | ||
authors = ["Philip Deljanov <philip.deljanov@gmail.com>"] | ||
license = "MPL-2.0" | ||
readme = "README.md" | ||
categories = ["multimedia", "multimedia::audio", "multimedia::encoding"] | ||
keywords = ["audio", "multimedia", "media", "mpeg"] | ||
edition = "2021" | ||
rust-version = "1.56" | ||
|
||
[dependencies] | ||
symphonia-core = { version = "0.5.4", path = "../symphonia-core" } | ||
symphonia-metadata = { version = "0.5.4", path = "../symphonia-metadata" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Symphonia Format Utilities | ||
|
||
[![Docs](https://docs.rs/symphonia-utils-format/badge.svg)](https://docs.rs/symphonia-utils-format) | ||
|
||
Common utilities for formats for Project Symphonia. | ||
|
||
**Note:** This crate is part of Symphonia. Please use the [`symphonia`](https://crates.io/crates/symphonia) crate instead of this one directly. | ||
|
||
## License | ||
|
||
Symphonia is provided under the MPL v2.0 license. Please refer to the LICENSE file for more details. | ||
|
||
## Contributing | ||
|
||
Symphonia is a free and open-source project that welcomes contributions! To get started, please read our [Contribution Guidelines](https://github.com/pdeljanov/Symphonia/tree/master/CONTRIBUTING.md). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Symphonia | ||
// Copyright (c) 2019-2022 The Project Symphonia Developers. | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
// The following lints are allowed in all Symphonia crates. Please see clippy.toml for their | ||
// justification. | ||
#![allow(clippy::comparison_chain)] | ||
#![allow(clippy::excessive_precision)] | ||
#![allow(clippy::identity_op)] | ||
#![allow(clippy::manual_range_contains)] | ||
|
||
pub mod video; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Symphonia | ||
// Copyright (c) 2019-2022 The Project Symphonia Developers. | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
use symphonia_core::codecs::CodecProfile; | ||
use symphonia_core::errors::{decode_error, Result}; | ||
use symphonia_core::io::{BitReaderLtr, ReadBitsLtr}; | ||
|
||
pub struct AVCDecoderConfigurationRecord { | ||
pub profile: CodecProfile, | ||
pub level: u32, | ||
} | ||
|
||
impl AVCDecoderConfigurationRecord { | ||
pub fn read(buf: &[u8]) -> Result<Self> { | ||
let mut br = BitReaderLtr::new(buf); | ||
|
||
// Parse the AVCDecoderConfigurationRecord to get the profile and level. Defined in | ||
// ISO/IEC 14496-15 section 5.3.3.1. | ||
|
||
// Configuration version is always 1. | ||
let configuration_version = br.read_bits_leq32(8)?; | ||
|
||
if configuration_version != 1 { | ||
return decode_error( | ||
"utils (avc): unexpected avc decoder configuration record version", | ||
); | ||
} | ||
|
||
// AVC profile as defined in ISO/IEC 14496-10. | ||
let avc_profile_indication = br.read_bits_leq32(8)?; | ||
let _profile_compatibility = br.read_bits_leq32(8)?; | ||
let avc_level_indication = br.read_bits_leq32(8)?; | ||
|
||
Ok(AVCDecoderConfigurationRecord { | ||
profile: CodecProfile::new(avc_profile_indication), | ||
level: avc_level_indication, | ||
}) | ||
} | ||
} | ||
|
||
pub struct HEVCDecoderConfigurationRecord { | ||
pub profile: CodecProfile, | ||
pub level: u32, | ||
} | ||
|
||
impl HEVCDecoderConfigurationRecord { | ||
pub fn read(buf: &[u8]) -> Result<Self> { | ||
let mut br = BitReaderLtr::new(buf); | ||
|
||
// Parse the HEVCDecoderConfigurationRecord to get the profile and level. Defined in | ||
// ISO/IEC 14496-15 section 8.3.3.1. | ||
|
||
// Configuration version is always 1. | ||
let configuration_version = br.read_bits_leq32(8)?; | ||
|
||
if configuration_version != 1 { | ||
return decode_error( | ||
"utils (hevc): unexpected hevc decoder configuration record version", | ||
); | ||
} | ||
|
||
let _general_profile_space = br.read_bits_leq32(2)?; | ||
let _general_tier_flag = br.read_bit()?; | ||
let general_profile_idc = br.read_bits_leq32(5)?; | ||
let _general_profile_compatibility_flags = br.read_bits_leq32(32)?; | ||
let _general_constraint_indicator_flags = br.read_bits_leq64(48)?; | ||
let general_level_idc = br.read_bits_leq32(8)?; | ||
|
||
Ok(HEVCDecoderConfigurationRecord { | ||
profile: CodecProfile::new(general_profile_idc), | ||
level: general_level_idc, | ||
}) | ||
} | ||
} |