• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "avmuxer_demo_runner.h"
17 #include <iostream>
18 #include <thread>
19 #include "avmuxer_demo.h"
20 #include "avmuxer_ffmpeg_demo.h"
21 #include "avmuxer_engine_demo.h"
22 #include "native_avmuxer_demo.h"
23 
24 using namespace std;
25 using namespace OHOS::MediaAVCodec;
26 using namespace OHOS::MediaAVCodec::Plugin;
27 
28 constexpr int RUN_TIME = 60000;
29 constexpr int DEMO_THREAD_COUNT = 10;
30 
RunLoopNativeMuxer(const string & out)31 static int RunLoopNativeMuxer(const string &out)
32 {
33     time_t startTime = 0;
34     time_t curTime = 0;
35     (void)time(&startTime);
36     (void)time(&curTime);
37     while (difftime(curTime, startTime) < RUN_TIME) {
38         RunNativeMuxer(out.c_str());
39         (void)time(&curTime);
40     }
41     return 0;
42 }
43 
RunAVMuxer()44 static int RunAVMuxer()
45 {
46     auto avmuxer = std::make_unique<AVMuxerDemo>();
47     avmuxer->RunCase();
48     cout << "demo avmuxer end" << endl;
49     return 0;
50 }
51 
RunAVMuxerWithMultithread()52 static int RunAVMuxerWithMultithread()
53 {
54     auto avmuxer = std::make_unique<AVMuxerDemo>();
55     avmuxer->RunMultiThreadCase();
56     cout << "demo multi thread avmuxer end" << endl;
57     return 0;
58 }
59 
RunFfmpegMuxer()60 static int RunFfmpegMuxer()
61 {
62     std::unique_ptr<AVMuxerDemoBase> ffmpegMuxer = std::make_unique<AVMuxerFFmpegDemo>();
63     ffmpegMuxer->RunCase();
64     cout << "demo ffmpegMuxer end" << endl;
65     return 0;
66 }
67 
RunEngineMuxer()68 static int RunEngineMuxer()
69 {
70     std::unique_ptr<AVMuxerDemoBase> muxer = std::make_unique<AVMuxerEngineDemo>();
71     muxer->RunCase();
72     cout << "demo engine demo end" << endl;
73     return 0;
74 }
75 
76 
RunLoopEngineMuxer()77 static int RunLoopEngineMuxer()
78 {
79     time_t startTime = 0;
80     time_t curTime = 0;
81     (void)time(&startTime);
82     (void)time(&curTime);
83     while (difftime(curTime, startTime) < RUN_TIME) {
84         RunEngineMuxer();
85         (void)time(&curTime);
86     }
87     return 0;
88 }
89 
AvmuxerDemoCase(void)90 void AvmuxerDemoCase(void)
91 {
92     cout << "Please select a muxer demo(default native muxer demo): " << endl;
93     cout << "0:native_muxer" << endl;
94     cout << "1:native_muxer loop" << endl;
95     cout << "2:native_muxer multithread" << endl;
96     cout << "3:inner_muxer" << endl;
97     cout << "4:inner_muxer with multithread write" << endl;
98     cout << "5:ffmpeg_muxer" << endl;
99     cout << "6:engine_muxer" << endl;
100     cout << "7:engine_muxer loop" << endl;
101 
102     string mode;
103     (void)getline(cin, mode);
104 
105     if (mode == "0" || mode == "") {
106         (void)NativeSelectMode();
107         (void)RunNativeMuxer("native_mux");
108     } else if (mode == "1") {
109         (void)NativeSelectMode();
110         (void)RunLoopNativeMuxer("loop_native_mux");
111     } else if (mode == "2") {
112         (void)NativeSelectMode();
113         vector<thread> vecThread;
114         for (int i = 0; i < DEMO_THREAD_COUNT; ++i) {
115             string out = to_string(i + 1);
116             out += "_native_mux";
117             vecThread.push_back(thread(RunLoopNativeMuxer, out));
118         }
119         for (int i = 0; i < DEMO_THREAD_COUNT; ++i) {
120             vecThread[i].join();
121         }
122     } else if (mode == "3") {
123         (void)RunAVMuxer();
124     } else if (mode == "4") {
125         (void)RunAVMuxerWithMultithread();
126     } else if (mode == "5") {
127         (void)RunFfmpegMuxer();
128     } else if (mode == "6") {
129         (void)RunEngineMuxer();
130     } else if (mode == "7") {
131         (void)RunLoopEngineMuxer();
132     }
133 }