feat_add_streaming-protocol_registry_to_multibuffer_data_source.patch 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 c19436994faa21246c8c2e53e96c7ce3fffede4f..31c2efe2acd8c11bb5a861fa42841fe0e76c1141 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/containers/adapters.h"
  18. #include "base/location.h"
  19. #include "base/memory/raw_ptr.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. @@ -67,8 +69,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. @@ -160,7 +174,14 @@ bool MultiBufferDataSource::media_has_played() const {
  47. bool MultiBufferDataSource::AssumeFullyBuffered() const {
  48. DCHECK(url_data_);
  49. - return !url_data_->url().ProtocolIsInHTTPFamily();
  50. +
  51. + const std::string scheme = url_data_->url().Protocol().Ascii();
  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(
  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 5277d480ce3ac065501a986b323e8f3a983acd75..6666dd87cd8971c7ed05a4bc141e19b9be549e54 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. @@ -17,6 +17,7 @@
  65. #include "media/base/data_source.h"
  66. #include "media/base/ranges.h"
  67. #include "media/base/tuneable.h"
  68. +#include "third_party/blink/public/platform/web_common.h"
  69. #include "third_party/blink/renderer/platform/media/url_index.h"
  70. #include "third_party/blink/renderer/platform/platform_export.h"
  71. #include "third_party/blink/renderer/platform/wtf/vector.h"
  72. @@ -34,6 +35,8 @@ namespace blink {
  73. class BufferedDataSourceHost;
  74. class MultiBufferReader;
  75. +void BLINK_PLATFORM_EXPORT AddStreamingScheme(const char* new_scheme);
  76. +
  77. // A data source capable of loading URLs and buffering the data using an
  78. // in-memory sliding window.
  79. //