HTMLMediaElement.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Copyright (c) 2020, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/ByteBuffer.h>
  8. #include <AK/Variant.h>
  9. #include <LibJS/SafeFunction.h>
  10. #include <LibWeb/HTML/EventLoop/Task.h>
  11. #include <LibWeb/HTML/HTMLElement.h>
  12. #include <math.h>
  13. namespace Web::HTML {
  14. class HTMLMediaElement : public HTMLElement {
  15. WEB_PLATFORM_OBJECT(HTMLMediaElement, HTMLElement);
  16. public:
  17. virtual ~HTMLMediaElement() override;
  18. void queue_a_media_element_task(JS::SafeFunction<void()> steps);
  19. enum class NetworkState : u16 {
  20. Empty,
  21. Idle,
  22. Loading,
  23. NoSource,
  24. };
  25. NetworkState network_state() const { return m_network_state; }
  26. WebIDL::ExceptionOr<Bindings::CanPlayTypeResult> can_play_type(DeprecatedString const& type) const;
  27. void load() const;
  28. double duration() const;
  29. void pause() const;
  30. JS::NonnullGCPtr<VideoTrackList> video_tracks() const { return *m_video_tracks; }
  31. protected:
  32. HTMLMediaElement(DOM::Document&, DOM::QualifiedName);
  33. virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
  34. virtual void visit_edges(Cell::Visitor&) override;
  35. private:
  36. struct EntireResource { };
  37. using ByteRange = Variant<EntireResource>; // FIXME: This will need to include "until end" and an actual byte range.
  38. virtual void parse_attribute(DeprecatedFlyString const& name, DeprecatedString const& value) override;
  39. Task::Source media_element_event_task_source() const { return m_media_element_event_task_source.source; }
  40. WebIDL::ExceptionOr<void> load_element();
  41. WebIDL::ExceptionOr<void> select_resource();
  42. WebIDL::ExceptionOr<void> fetch_resource(AK::URL const&, Function<void()> failure_callback);
  43. static bool verify_response(JS::NonnullGCPtr<Fetch::Infrastructure::Response>, ByteRange const&);
  44. WebIDL::ExceptionOr<void> process_media_data(Function<void()> failure_callback);
  45. WebIDL::ExceptionOr<void> handle_media_source_failure();
  46. void forget_media_resource_specific_tracks();
  47. void set_duration(double);
  48. // https://html.spec.whatwg.org/multipage/media.html#media-element-event-task-source
  49. UniqueTaskSource m_media_element_event_task_source {};
  50. // https://html.spec.whatwg.org/multipage/media.html#dom-media-networkstate
  51. NetworkState m_network_state { NetworkState::Empty };
  52. // https://html.spec.whatwg.org/multipage/media.html#dom-media-duration
  53. double m_duration { NAN };
  54. // https://html.spec.whatwg.org/multipage/media.html#dom-media-videotracks
  55. JS::GCPtr<VideoTrackList> m_video_tracks;
  56. // https://html.spec.whatwg.org/multipage/media.html#media-data
  57. ByteBuffer m_media_data;
  58. JS::GCPtr<Fetch::Infrastructure::FetchController> m_fetch_controller;
  59. };
  60. }