• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #include "webrtc/modules/video_coding/main/test/receiver_tests.h"
12 #include "webrtc/modules/video_coding/main/test/vcm_payload_sink_factory.h"
13 #include "webrtc/system_wrappers/interface/trace.h"
14 #include "webrtc/test/testsupport/fileutils.h"
15 
16 namespace {
17 
18 const bool kConfigProtectionEnabled = true;
19 const webrtc::VCMVideoProtection kConfigProtectionMethod =
20     webrtc::kProtectionNack;
21 const float kConfigLossRate = 0.0f;
22 const bool kConfigReordering = false;
23 const uint32_t kConfigRttMs = 0;
24 const uint32_t kConfigRenderDelayMs = 0;
25 const uint32_t kConfigMinPlayoutDelayMs = 0;
26 const int64_t kConfigMaxRuntimeMs = -1;
27 
28 }  // namespace
29 
RtpPlay(const CmdArgs & args)30 int RtpPlay(const CmdArgs& args) {
31   std::string trace_file = webrtc::test::OutputPath() + "receiverTestTrace.txt";
32   webrtc::Trace::CreateTrace();
33   webrtc::Trace::SetTraceFile(trace_file.c_str());
34   webrtc::Trace::set_level_filter(webrtc::kTraceAll);
35 
36   webrtc::rtpplayer::PayloadTypes payload_types;
37   payload_types.push_back(webrtc::rtpplayer::PayloadCodecTuple(
38       VCM_ULPFEC_PAYLOAD_TYPE, "ULPFEC", webrtc::kVideoCodecULPFEC));
39   payload_types.push_back(webrtc::rtpplayer::PayloadCodecTuple(
40       VCM_RED_PAYLOAD_TYPE, "RED", webrtc::kVideoCodecRED));
41   payload_types.push_back(webrtc::rtpplayer::PayloadCodecTuple(
42       VCM_VP8_PAYLOAD_TYPE, "VP8", webrtc::kVideoCodecVP8));
43 
44   std::string output_file = args.outputFile;
45   if (output_file == "") {
46     output_file = webrtc::test::OutputPath() + "RtpPlay_decoded.yuv";
47   }
48 
49   webrtc::SimulatedClock clock(0);
50   webrtc::rtpplayer::VcmPayloadSinkFactory factory(output_file, &clock,
51       kConfigProtectionEnabled, kConfigProtectionMethod, kConfigRttMs,
52       kConfigRenderDelayMs, kConfigMinPlayoutDelayMs);
53   webrtc::scoped_ptr<webrtc::rtpplayer::RtpPlayerInterface> rtp_player(
54       webrtc::rtpplayer::Create(args.inputFile, &factory, &clock, payload_types,
55           kConfigLossRate, kConfigRttMs, kConfigReordering));
56   if (rtp_player.get() == NULL) {
57     return -1;
58   }
59 
60   int ret = 0;
61   while ((ret = rtp_player->NextPacket(clock.TimeInMilliseconds())) == 0) {
62     ret = factory.DecodeAndProcessAll(true);
63     if (ret < 0 || (kConfigMaxRuntimeMs > -1 &&
64         clock.TimeInMilliseconds() >= kConfigMaxRuntimeMs)) {
65       break;
66     }
67     clock.AdvanceTimeMilliseconds(1);
68   }
69 
70   rtp_player->Print();
71 
72   switch (ret) {
73     case 1:
74       printf("Success\n");
75       return 0;
76     case -1:
77       printf("Failed\n");
78       return -1;
79     case 0:
80       printf("Timeout\n");
81       return -1;
82   }
83 
84   webrtc::Trace::ReturnTrace();
85   return 0;
86 }
87