1b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org/*
2b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org *
4b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org *  Use of this source code is governed by a BSD-style license
5b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org *  that can be found in the LICENSE file in the root of the source
6b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org *  tree. An additional intellectual property rights grant can be found
7b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org *  in the file PATENTS.  All contributing project authors may
8b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org *  be found in the AUTHORS file in the root of the source tree.
9b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org */
10b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org
112637d61b86b68c7082ae21b4cc9bc88cc36d1c13stefan@webrtc.org#include "webrtc/modules/video_coding/main/test/receiver_tests.h"
124d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org#include "webrtc/modules/video_coding/main/test/vcm_payload_sink_factory.h"
132637d61b86b68c7082ae21b4cc9bc88cc36d1c13stefan@webrtc.org#include "webrtc/system_wrappers/interface/trace.h"
144d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org#include "webrtc/test/testsupport/fileutils.h"
154d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org
164d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.orgnamespace {
174d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org
184d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.orgconst bool kConfigProtectionEnabled = true;
194d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.orgconst webrtc::VCMVideoProtection kConfigProtectionMethod =
204d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org    webrtc::kProtectionNack;
214d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.orgconst float kConfigLossRate = 0.0f;
224d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.orgconst bool kConfigReordering = false;
234d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.orgconst uint32_t kConfigRttMs = 0;
244d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.orgconst uint32_t kConfigRenderDelayMs = 0;
254d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.orgconst uint32_t kConfigMinPlayoutDelayMs = 0;
264d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.orgconst int64_t kConfigMaxRuntimeMs = -1;
274d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org
283b89e10f31160da35b408fd00cb8f89d2b08862dpbos@webrtc.org}  // namespace
294d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org
304d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.orgint RtpPlay(const CmdArgs& args) {
314d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org  std::string trace_file = webrtc::test::OutputPath() + "receiverTestTrace.txt";
324d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org  webrtc::Trace::CreateTrace();
334d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org  webrtc::Trace::SetTraceFile(trace_file.c_str());
3406eaa5465d57f416c14bb3a587ba4146290d6a58andrew@webrtc.org  webrtc::Trace::set_level_filter(webrtc::kTraceAll);
354d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org
364d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org  webrtc::rtpplayer::PayloadTypes payload_types;
374d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org  payload_types.push_back(webrtc::rtpplayer::PayloadCodecTuple(
384d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org      VCM_ULPFEC_PAYLOAD_TYPE, "ULPFEC", webrtc::kVideoCodecULPFEC));
394d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org  payload_types.push_back(webrtc::rtpplayer::PayloadCodecTuple(
404d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org      VCM_RED_PAYLOAD_TYPE, "RED", webrtc::kVideoCodecRED));
414d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org  payload_types.push_back(webrtc::rtpplayer::PayloadCodecTuple(
424d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org      VCM_VP8_PAYLOAD_TYPE, "VP8", webrtc::kVideoCodecVP8));
434d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org
444d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org  std::string output_file = args.outputFile;
454d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org  if (output_file == "") {
464d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org    output_file = webrtc::test::OutputPath() + "RtpPlay_decoded.yuv";
47b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org  }
48b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org
494d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org  webrtc::SimulatedClock clock(0);
504d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org  webrtc::rtpplayer::VcmPayloadSinkFactory factory(output_file, &clock,
514d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org      kConfigProtectionEnabled, kConfigProtectionMethod, kConfigRttMs,
5231a8ce783a62afe0c014bc23f0be8c2a779dbd74mikhal@webrtc.org      kConfigRenderDelayMs, kConfigMinPlayoutDelayMs);
534d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org  webrtc::scoped_ptr<webrtc::rtpplayer::RtpPlayerInterface> rtp_player(
544d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org      webrtc::rtpplayer::Create(args.inputFile, &factory, &clock, payload_types,
554d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org          kConfigLossRate, kConfigRttMs, kConfigReordering));
564d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org  if (rtp_player.get() == NULL) {
574d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org    return -1;
584d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org  }
59b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org
604d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org  int ret = 0;
614d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org  while ((ret = rtp_player->NextPacket(clock.TimeInMilliseconds())) == 0) {
624d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org    ret = factory.DecodeAndProcessAll(true);
634d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org    if (ret < 0 || (kConfigMaxRuntimeMs > -1 &&
644d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org        clock.TimeInMilliseconds() >= kConfigMaxRuntimeMs)) {
654d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org      break;
66b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org    }
674d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org    clock.AdvanceTimeMilliseconds(1);
684d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org  }
69b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org
704d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org  rtp_player->Print();
718edb4a7b3766052d900f46a0bc84f9bab94cc83fstefan@webrtc.org
724d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org  switch (ret) {
738edb4a7b3766052d900f46a0bc84f9bab94cc83fstefan@webrtc.org    case 1:
744d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org      printf("Success\n");
754d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org      return 0;
768edb4a7b3766052d900f46a0bc84f9bab94cc83fstefan@webrtc.org    case -1:
774d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org      printf("Failed\n");
784d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org      return -1;
798edb4a7b3766052d900f46a0bc84f9bab94cc83fstefan@webrtc.org    case 0:
804d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org      printf("Timeout\n");
814d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org      return -1;
824d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org  }
834d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org
844d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org  webrtc::Trace::ReturnTrace();
854d2a2eccaef42c24ada13e98fe2917439d882033solenberg@webrtc.org  return 0;
86b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org}
87