1 /*
2 * Copyright (c) 2019, Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22 
23 //!
24 //! \file     decode_sub_pipeline_manager.cpp
25 //! \brief    Defines the common interface for decode sub pipeline manager
26 //! \details  Defines the common interface for decode sub pipeline manager
27 //!
28 #include "decode_sub_pipeline.h"
29 #include "decode_pipeline.h"
30 #include "decode_utils.h"
31 #include "media_packet.h"
32 
33 namespace decode {
34 
DecodeSubPipelineManager(DecodePipeline & decodePipeline)35 DecodeSubPipelineManager::DecodeSubPipelineManager(DecodePipeline& decodePipeline)
36 {
37     m_decodePipeline = &decodePipeline;
38 }
39 
~DecodeSubPipelineManager()40 DecodeSubPipelineManager::~DecodeSubPipelineManager()
41 {
42     Destroy(m_subPipelineList);
43 }
44 
Register(DecodeSubPipeline & subPipeline)45 MOS_STATUS DecodeSubPipelineManager::Register(DecodeSubPipeline& subPipeline)
46 {
47     m_subPipelineList.push_back(&subPipeline);
48     return MOS_STATUS_SUCCESS;
49 }
50 
Init(CodechalSetting & settings)51 MOS_STATUS DecodeSubPipelineManager::Init(CodechalSetting& settings)
52 {
53     for (auto subPipeline : m_subPipelineList)
54     {
55         DECODE_CHK_STATUS(subPipeline->Init(settings));
56     }
57     return MOS_STATUS_SUCCESS;
58 }
59 
Prepare(DecodePipelineParams & params)60 MOS_STATUS DecodeSubPipelineManager::Prepare(DecodePipelineParams& params)
61 {
62     for (auto subPipeline : m_subPipelineList)
63     {
64         DECODE_CHK_STATUS(subPipeline->Prepare(params));
65     }
66     return MOS_STATUS_SUCCESS;
67 }
68 
ExecuteSubPipeline(DecodeSubPipeline & subPipeline)69 MOS_STATUS DecodeSubPipelineManager::ExecuteSubPipeline(DecodeSubPipeline &subPipeline)
70 {
71     auto& subActivePackets = subPipeline.GetActivePackets();
72     if (subActivePackets.size() == 0)
73     {
74         return MOS_STATUS_SUCCESS;
75     }
76 
77     MediaContext *mediaContext = m_decodePipeline->GetMediaContext();
78     DECODE_CHK_NULL(mediaContext);
79 
80     MediaFunction mediaFunction = subPipeline.GetMediaFunction();
81     DecodeScalabilityPars& scalPars = subPipeline.GetScalabilityPars();
82     auto& scalability = m_decodePipeline->GetMediaScalability();
83     DECODE_CHK_STATUS(mediaContext->SwitchContext(mediaFunction, &scalPars, &scalability));
84 
85     auto& subPacketList = subPipeline.GetPacketList();
86     std::swap(subPacketList, m_decodePipeline->m_packetList);
87     std::swap(subActivePackets, m_decodePipeline->m_activePacketList);
88 
89     DECODE_CHK_STATUS(m_decodePipeline->ExecuteActivePackets());
90 
91     std::swap(subPacketList, m_decodePipeline->m_packetList);
92     std::swap(subActivePackets, m_decodePipeline->m_activePacketList);
93 
94     return MOS_STATUS_SUCCESS;
95 }
96 
Execute()97 MOS_STATUS DecodeSubPipelineManager::Execute()
98 {
99     for (auto subPipeline : m_subPipelineList)
100     {
101         DECODE_CHK_STATUS(ExecuteSubPipeline(*subPipeline));
102     }
103     return MOS_STATUS_SUCCESS;
104 }
105 
Destroy(std::vector<DecodeSubPipeline * > & subPipelineList)106 void DecodeSubPipelineManager::Destroy(std::vector<DecodeSubPipeline *> &subPipelineList)
107 {
108     for (auto subPipeline : subPipelineList)
109     {
110         MOS_Delete(subPipeline);
111     }
112     subPipelineList.clear();
113 }
114 
115 }
116