Skip to main content

stream_processor_decoder_factory/
decoders.rs

1// Copyright 2019 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5use fidl::endpoints::*;
6use fidl_fuchsia_media::*;
7use fidl_fuchsia_mediacodec::*;
8use fuchsia_component::client;
9use futures::FutureExt;
10use futures::future::{self, BoxFuture};
11use stream_processor_test::*;
12
13pub struct DecoderFactory;
14
15impl StreamProcessorFactory for DecoderFactory {
16    fn connect_to_stream_processor(
17        &self,
18        stream: &dyn ElementaryStream,
19        format_details_version_ordinal: u64,
20    ) -> BoxFuture<'_, Result<StreamProcessorProxy>> {
21        DecoderFactoryWithParams { require_sw: None }
22            .connect_to_stream_processor(stream, format_details_version_ordinal)
23    }
24}
25
26pub struct DecoderFactoryWithParams {
27    pub require_sw: Option<bool>,
28}
29
30impl StreamProcessorFactory for DecoderFactoryWithParams {
31    fn connect_to_stream_processor(
32        &self,
33        stream: &dyn ElementaryStream,
34        format_details_version_ordinal: u64,
35    ) -> BoxFuture<'_, Result<StreamProcessorProxy>> {
36        let require_sw = self.require_sw;
37        let get_decoder = move || {
38            let factory = client::connect_to_protocol::<CodecFactoryMarker>()?;
39            let (decoder_client_end, decoder_request) = create_endpoints();
40            let decoder = decoder_client_end.into_proxy();
41            // TODO(turnage): Account for all error reporting methods in the
42            // runner options and output.
43            factory.create_decoder(
44                &CreateDecoderParams {
45                    input_details: Some(stream.format_details(format_details_version_ordinal)),
46                    promise_separate_access_units_on_input: Some(stream.is_access_units()),
47                    permit_lack_of_split_header_handling: Some(true),
48                    require_sw,
49                    ..Default::default()
50                },
51                decoder_request,
52            )?;
53            Ok(decoder)
54        };
55        future::ready(get_decoder()).boxed()
56    }
57}