feat_add_streaming-protocol_registry_to_multibuffer_data_source.patch 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Paul Frazee <[email protected]>
  3. Date: Sat, 6 Jun 2020 10:30:45 -0500
  4. Subject: feat: add streaming-protocol registry to multibuffer_data_source
  5. blink::WebMediaPlayerImpl - which provides the <video> and <audio> behaviors - needs to know
  6. whether a data source will stream or fully buffer the response. It determines this behavior
  7. with MultibufferDataSource::AssumeFullyBuffered() which has http/s hardwired. An incorrect
  8. determination will cause the video/audio to fail playing.
  9. This patch adds a list of "streaming protocols" to the MultibufferDataSource in order to allow
  10. other protocols to register their streaming behavior. MultibufferDataSource::AssumeFullyBuffered()
  11. then refers to the list so that it can correctly determine the data source's settings.
  12. diff --git a/third_party/blink/renderer/platform/media/multi_buffer_data_source.cc b/third_party/blink/renderer/platform/media/multi_buffer_data_source.cc
  13. index 2b5c5f059159865cb84a7efcefe47cd788d5f5ee..1627649fb5085c637cde556074b242c4939c81de 100644
  14. --- a/third_party/blink/renderer/platform/media/multi_buffer_data_source.cc
  15. +++ b/third_party/blink/renderer/platform/media/multi_buffer_data_source.cc
  16. @@ -11,8 +11,10 @@
  17. #include "base/functional/bind.h"
  18. #include "base/functional/callback_helpers.h"
  19. #include "base/location.h"
  20. +#include "base/no_destructor.h"
  21. #include "base/numerics/safe_conversions.h"
  22. #include "base/task/single_thread_task_runner.h"
  23. +#include "base/strings/string_util.h"
  24. #include "media/base/media_log.h"
  25. #include "net/base/net_errors.h"
  26. #include "third_party/blink/renderer/platform/media/buffered_data_source_host_impl.h"
  27. @@ -61,8 +63,20 @@ const int kUpdateBufferSizeFrequency = 32;
  28. // How long to we delay a seek after a read?
  29. constexpr base::TimeDelta kSeekDelay = base::Milliseconds(20);
  30. +std::vector<std::string>* GetStreamingSchemes() {
  31. + static base::NoDestructor<std::vector<std::string>> streaming_schemes({
  32. + url::kHttpsScheme,
  33. + url::kHttpScheme
  34. + });
  35. + return streaming_schemes.get();
  36. +}
  37. +
  38. } // namespace
  39. +void AddStreamingScheme(const char* new_scheme) {
  40. + GetStreamingSchemes()->push_back(new_scheme);
  41. +}
  42. +
  43. class MultiBufferDataSource::ReadOperation {
  44. public:
  45. ReadOperation() = delete;
  46. @@ -154,7 +168,14 @@ bool MultiBufferDataSource::media_has_played() const {
  47. bool MultiBufferDataSource::AssumeFullyBuffered() const {
  48. DCHECK(url_data_);
  49. - return !url_data_->url().SchemeIsHTTPOrHTTPS();
  50. +
  51. + const std::string scheme = url_data_->url().scheme();
  52. + for (const std::string& streaming_scheme : *GetStreamingSchemes()) {
  53. + if (base::EqualsCaseInsensitiveASCII(scheme, streaming_scheme)) {
  54. + return false;
  55. + }
  56. + }
  57. + return true;
  58. }
  59. void MultiBufferDataSource::SetReader(MultiBufferReader* reader) {
  60. diff --git a/third_party/blink/renderer/platform/media/multi_buffer_data_source.h b/third_party/blink/renderer/platform/media/multi_buffer_data_source.h
  61. index 29ca8efb5994ccb5b65d2762088dd53e0583cb72..c533149f567731e6bb6ed2d94dcffd03346f7f87 100644
  62. --- a/third_party/blink/renderer/platform/media/multi_buffer_data_source.h
  63. +++ b/third_party/blink/renderer/platform/media/multi_buffer_data_source.h
  64. @@ -33,6 +33,8 @@ namespace blink {
  65. class BufferedDataSourceHost;
  66. class MultiBufferReader;
  67. +void BLINK_PLATFORM_EXPORT AddStreamingScheme(const char* new_scheme);
  68. +
  69. // A data source capable of loading URLs and buffering the data using an
  70. // in-memory sliding window.
  71. //