Index: webrtc/modules/video_coding/h264_sprop_parameter_sets.cc |
diff --git a/webrtc/modules/video_coding/h264_sprop_parameter_sets.cc b/webrtc/modules/video_coding/h264_sprop_parameter_sets.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d50c783534618d1eae8b579fba043197719f21ed |
--- /dev/null |
+++ b/webrtc/modules/video_coding/h264_sprop_parameter_sets.cc |
@@ -0,0 +1,58 @@ |
+/* |
+ * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
+ * |
+ * Use of this source code is governed by a BSD-style license |
+ * that can be found in the LICENSE file in the root of the source |
+ * tree. An additional intellectual property rights grant can be found |
+ * in the file PATENTS. All contributing project authors may |
+ * be found in the AUTHORS file in the root of the source tree. |
+ */ |
+ |
+#include "webrtc/modules/video_coding/h264_sprop_parameter_sets.h" |
+ |
+#include "webrtc/base/base64.h" |
+#include "webrtc/base/bitbuffer.h" |
+#include "webrtc/base/bytebuffer.h" |
+#include "webrtc/base/logging.h" |
+ |
+namespace webrtc { |
+ |
+static bool DecodeAndConvert(const std::string& base64, |
+ std::vector<uint8_t>* binary) { |
sprang_webrtc
2016/12/06 18:23:18
Why static?
We usually just put these kind of hel
johan
2016/12/07 17:10:40
Well, old habit from plain c days. *In this place*
|
+ static constexpr rtc::Base64::DecodeFlags flags = rtc::Base64::DO_STRICT; |
+ // TODO(johan): Directly decode to std::vector<uint8_t> when available. |
+ std::vector<char> tmp; |
+ bool success = rtc::Base64::DecodeFromArray(base64.data(), base64.size(), |
+ flags, &tmp, nullptr); |
+ if (!success) { |
sprang_webrtc
2016/12/06 18:23:18
Don't need this temporary, just if (!DecodeFromArr
johan
2016/12/07 17:10:40
Done.
sprang_webrtc
2016/12/08 10:08:37
Seems to still be there?
|
+ return false; |
+ } |
+ const uint8_t* data = reinterpret_cast<uint8_t*>(tmp.data()); |
+ binary->assign(data, data + tmp.size()); |
+ return success; |
+} |
+ |
+bool H264SpropParameterSets::DecodeSprop(const std::string& sprop) { |
+ size_t separator_pos = sprop.find(','); |
+ if ((separator_pos <= 0) || (separator_pos >= sprop.length() - 1)) { |
+ LOG(LS_WARNING) << "Invalid seperator position " << separator_pos << " *" |
+ << sprop << "*"; |
+ return false; |
+ } |
+ std::string sps_str = sprop.substr(0, separator_pos); |
+ std::string pps_str = sprop.substr(separator_pos + 1, std::string::npos); |
+ bool success; |
sprang_webrtc
2016/12/06 18:23:18
dito
johan
2016/12/07 17:10:40
Done.
|
+ success = DecodeAndConvert(sps_str, &sps_); |
+ if (!success) { |
+ LOG(LS_WARNING) << "Failed to decode sps *" << sprop << "*"; |
sprang_webrtc
2016/12/06 18:23:18
Should that be sps_str?
johan
2016/12/07 17:10:40
Actually I want to output the entire string in cas
|
+ return false; |
+ } |
+ success = DecodeAndConvert(pps_str, &pps_); |
+ if (!success) { |
+ LOG(LS_WARNING) << "Failed to decode pps *" << sprop << "*"; |
+ return false; |
+ } |
+ return true; |
+} |
+ |
+} // namespace webrtc |