| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 size_t encoded_bytes() { return encoded_bytes_; } | 35 size_t encoded_bytes() { return encoded_bytes_; } |
| 36 | 36 |
| 37 private: | 37 private: |
| 38 webrtc::EncodedImage encoded_image_; | 38 webrtc::EncodedImage encoded_image_; |
| 39 FILE* encoded_file_; | 39 FILE* encoded_file_; |
| 40 size_t encoded_bytes_; | 40 size_t encoded_bytes_; |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 Vp8SequenceCoderEncodeCallback::~Vp8SequenceCoderEncodeCallback() { | 43 Vp8SequenceCoderEncodeCallback::~Vp8SequenceCoderEncodeCallback() { |
| 44 delete[] encoded_image_._buffer; | 44 delete[] encoded_image_._buffer; |
| 45 encoded_image_._buffer = NULL; | 45 encoded_image_._buffer = nullptr; |
| 46 } | 46 } |
| 47 | 47 |
| 48 webrtc::EncodedImageCallback::Result | 48 webrtc::EncodedImageCallback::Result |
| 49 Vp8SequenceCoderEncodeCallback::OnEncodedImage( | 49 Vp8SequenceCoderEncodeCallback::OnEncodedImage( |
| 50 const webrtc::EncodedImage& encoded_image, | 50 const webrtc::EncodedImage& encoded_image, |
| 51 const webrtc::CodecSpecificInfo* codecSpecificInfo, | 51 const webrtc::CodecSpecificInfo* codecSpecificInfo, |
| 52 const webrtc::RTPFragmentationHeader* fragmentation) { | 52 const webrtc::RTPFragmentationHeader* fragmentation) { |
| 53 if (encoded_image_._size < encoded_image._size) { | 53 if (encoded_image_._size < encoded_image._size) { |
| 54 delete[] encoded_image_._buffer; | 54 delete[] encoded_image_._buffer; |
| 55 encoded_image_._buffer = NULL; | 55 encoded_image_._buffer = nullptr; |
| 56 encoded_image_._buffer = new uint8_t[encoded_image._size]; | 56 encoded_image_._buffer = new uint8_t[encoded_image._size]; |
| 57 encoded_image_._size = encoded_image._size; | 57 encoded_image_._size = encoded_image._size; |
| 58 } | 58 } |
| 59 memcpy(encoded_image_._buffer, encoded_image._buffer, encoded_image._size); | 59 memcpy(encoded_image_._buffer, encoded_image._buffer, encoded_image._size); |
| 60 encoded_image_._length = encoded_image._length; | 60 encoded_image_._length = encoded_image._length; |
| 61 if (encoded_file_ != NULL) { | 61 if (encoded_file_ != nullptr) { |
| 62 if (fwrite(encoded_image._buffer, 1, encoded_image._length, | 62 if (fwrite(encoded_image._buffer, 1, encoded_image._length, |
| 63 encoded_file_) != encoded_image._length) { | 63 encoded_file_) != encoded_image._length) { |
| 64 return Result(Result::ERROR_SEND_FAILED, 0); | 64 return Result(Result::ERROR_SEND_FAILED, 0); |
| 65 } | 65 } |
| 66 } | 66 } |
| 67 encoded_bytes_ += encoded_image_._length; | 67 encoded_bytes_ += encoded_image_._length; |
| 68 return Result(Result::OK, 0); | 68 return Result(Result::OK, 0); |
| 69 } | 69 } |
| 70 | 70 |
| 71 // TODO(mikhal): Add support for varying the frame size. | 71 // TODO(mikhal): Add support for varying the frame size. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 83 private: | 83 private: |
| 84 FILE* decoded_file_; | 84 FILE* decoded_file_; |
| 85 }; | 85 }; |
| 86 | 86 |
| 87 int Vp8SequenceCoderDecodeCallback::Decoded(webrtc::VideoFrame& image) { | 87 int Vp8SequenceCoderDecodeCallback::Decoded(webrtc::VideoFrame& image) { |
| 88 EXPECT_EQ(0, webrtc::PrintVideoFrame(image, decoded_file_)); | 88 EXPECT_EQ(0, webrtc::PrintVideoFrame(image, decoded_file_)); |
| 89 return 0; | 89 return 0; |
| 90 } | 90 } |
| 91 | 91 |
| 92 int SequenceCoder(webrtc::test::CommandLineParser* parser) { | 92 int SequenceCoder(webrtc::test::CommandLineParser* parser) { |
| 93 int width = strtol((parser->GetFlag("w")).c_str(), NULL, 10); | 93 int width = strtol((parser->GetFlag("w")).c_str(), nullptr, 10); |
| 94 int height = strtol((parser->GetFlag("h")).c_str(), NULL, 10); | 94 int height = strtol((parser->GetFlag("h")).c_str(), nullptr, 10); |
| 95 int framerate = strtol((parser->GetFlag("f")).c_str(), NULL, 10); | 95 int framerate = strtol((parser->GetFlag("f")).c_str(), nullptr, 10); |
| 96 | 96 |
| 97 if (width <= 0 || height <= 0 || framerate <= 0) { | 97 if (width <= 0 || height <= 0 || framerate <= 0) { |
| 98 fprintf(stderr, "Error: Resolution cannot be <= 0!\n"); | 98 fprintf(stderr, "Error: Resolution cannot be <= 0!\n"); |
| 99 return -1; | 99 return -1; |
| 100 } | 100 } |
| 101 int target_bitrate = strtol((parser->GetFlag("b")).c_str(), NULL, 10); | 101 int target_bitrate = strtol((parser->GetFlag("b")).c_str(), nullptr, 10); |
| 102 if (target_bitrate <= 0) { | 102 if (target_bitrate <= 0) { |
| 103 fprintf(stderr, "Error: Bit-rate cannot be <= 0!\n"); | 103 fprintf(stderr, "Error: Bit-rate cannot be <= 0!\n"); |
| 104 return -1; | 104 return -1; |
| 105 } | 105 } |
| 106 | 106 |
| 107 // SetUp | 107 // SetUp |
| 108 // Open input file. | 108 // Open input file. |
| 109 std::string encoded_file_name = parser->GetFlag("encoded_file"); | 109 std::string encoded_file_name = parser->GetFlag("encoded_file"); |
| 110 FILE* encoded_file = fopen(encoded_file_name.c_str(), "wb"); | 110 FILE* encoded_file = fopen(encoded_file_name.c_str(), "wb"); |
| 111 if (encoded_file == NULL) { | 111 if (encoded_file == nullptr) { |
| 112 fprintf(stderr, "Error: Cannot open encoded file\n"); | 112 fprintf(stderr, "Error: Cannot open encoded file\n"); |
| 113 return -1; | 113 return -1; |
| 114 } | 114 } |
| 115 std::string input_file_name = parser->GetFlag("input_file"); | 115 std::string input_file_name = parser->GetFlag("input_file"); |
| 116 FILE* input_file = fopen(input_file_name.c_str(), "rb"); | 116 FILE* input_file = fopen(input_file_name.c_str(), "rb"); |
| 117 if (input_file == NULL) { | 117 if (input_file == nullptr) { |
| 118 fprintf(stderr, "Error: Cannot open input file\n"); | 118 fprintf(stderr, "Error: Cannot open input file\n"); |
| 119 return -1; | 119 return -1; |
| 120 } | 120 } |
| 121 // Open output file. | 121 // Open output file. |
| 122 std::string output_file_name = parser->GetFlag("output_file"); | 122 std::string output_file_name = parser->GetFlag("output_file"); |
| 123 FILE* output_file = fopen(output_file_name.c_str(), "wb"); | 123 FILE* output_file = fopen(output_file_name.c_str(), "wb"); |
| 124 if (output_file == NULL) { | 124 if (output_file == nullptr) { |
| 125 fprintf(stderr, "Error: Cannot open output file\n"); | 125 fprintf(stderr, "Error: Cannot open output file\n"); |
| 126 return -1; | 126 return -1; |
| 127 } | 127 } |
| 128 | 128 |
| 129 // Get range of frames: will encode num_frames following start_frame). | 129 // Get range of frames: will encode num_frames following start_frame). |
| 130 int start_frame = strtol((parser->GetFlag("start_frame")).c_str(), NULL, 10); | 130 int start_frame = |
| 131 int num_frames = strtol((parser->GetFlag("num_frames")).c_str(), NULL, 10); | 131 strtol((parser->GetFlag("start_frame")).c_str(), nullptr, 10); |
| 132 int num_frames = strtol((parser->GetFlag("num_frames")).c_str(), nullptr, 10); |
| 132 | 133 |
| 133 // Codec SetUp. | 134 // Codec SetUp. |
| 134 webrtc::VideoCodec inst; | 135 webrtc::VideoCodec inst; |
| 135 memset(&inst, 0, sizeof(inst)); | 136 memset(&inst, 0, sizeof(inst)); |
| 136 webrtc::VP8Encoder* encoder = webrtc::VP8Encoder::Create(); | 137 webrtc::VP8Encoder* encoder = webrtc::VP8Encoder::Create(); |
| 137 webrtc::VP8Decoder* decoder = webrtc::VP8Decoder::Create(); | 138 webrtc::VP8Decoder* decoder = webrtc::VP8Decoder::Create(); |
| 138 inst.codecType = webrtc::kVideoCodecVP8; | 139 inst.codecType = webrtc::kVideoCodecVP8; |
| 139 inst.VP8()->feedbackModeOn = false; | 140 inst.VP8()->feedbackModeOn = false; |
| 140 inst.VP8()->denoisingOn = true; | 141 inst.VP8()->denoisingOn = true; |
| 141 inst.maxFramerate = framerate; | 142 inst.maxFramerate = framerate; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 165 int frame_cnt = 1; | 166 int frame_cnt = 1; |
| 166 int frames_processed = 0; | 167 int frames_processed = 0; |
| 167 while (num_frames == -1 || frames_processed < num_frames) { | 168 while (num_frames == -1 || frames_processed < num_frames) { |
| 168 rtc::scoped_refptr<VideoFrameBuffer> buffer( | 169 rtc::scoped_refptr<VideoFrameBuffer> buffer( |
| 169 test::ReadI420Buffer(width, height, input_file)); | 170 test::ReadI420Buffer(width, height, input_file)); |
| 170 if (!buffer) { | 171 if (!buffer) { |
| 171 // EOF or read error. | 172 // EOF or read error. |
| 172 break; | 173 break; |
| 173 } | 174 } |
| 174 if (frame_cnt >= start_frame) { | 175 if (frame_cnt >= start_frame) { |
| 175 encoder->Encode(VideoFrame(buffer, webrtc::kVideoRotation_0, 0), | 176 encoder->Encode(VideoFrame(buffer, webrtc::kVideoRotation_0, 0), nullptr, |
| 176 NULL, NULL); | 177 nullptr); |
| 177 decoder->Decode(encoder_callback.encoded_image(), false, NULL); | 178 decoder->Decode(encoder_callback.encoded_image(), false, nullptr); |
| 178 ++frames_processed; | 179 ++frames_processed; |
| 179 } | 180 } |
| 180 ++frame_cnt; | 181 ++frame_cnt; |
| 181 } | 182 } |
| 182 printf("\nProcessed %d frames\n", frames_processed); | 183 printf("\nProcessed %d frames\n", frames_processed); |
| 183 int64_t endtime = rtc::TimeMillis(); | 184 int64_t endtime = rtc::TimeMillis(); |
| 184 int64_t totalExecutionTime = endtime - starttime; | 185 int64_t totalExecutionTime = endtime - starttime; |
| 185 printf("Total execution time: %.2lf ms\n", | 186 printf("Total execution time: %.2lf ms\n", |
| 186 static_cast<double>(totalExecutionTime)); | 187 static_cast<double>(totalExecutionTime)); |
| 187 double actual_bit_rate = | 188 double actual_bit_rate = |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 | 242 |
| 242 parser.ProcessFlags(); | 243 parser.ProcessFlags(); |
| 243 if (parser.GetFlag("help") == "true") { | 244 if (parser.GetFlag("help") == "true") { |
| 244 parser.PrintUsageMessage(); | 245 parser.PrintUsageMessage(); |
| 245 exit(EXIT_SUCCESS); | 246 exit(EXIT_SUCCESS); |
| 246 } | 247 } |
| 247 parser.PrintEnteredFlags(); | 248 parser.PrintEnteredFlags(); |
| 248 | 249 |
| 249 return SequenceCoder(&parser); | 250 return SequenceCoder(&parser); |
| 250 } | 251 } |
| OLD | NEW |