OfflineAudioContext.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright (c) 2024, Shannon Booth <shannon@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibWeb/Bindings/OfflineAudioContextPrototype.h>
  8. #include <LibWeb/HighResolutionTime/DOMHighResTimeStamp.h>
  9. #include <LibWeb/WebAudio/BaseAudioContext.h>
  10. #include <LibWeb/WebIDL/Types.h>
  11. namespace Web::WebAudio {
  12. // https://webaudio.github.io/web-audio-api/#OfflineAudioContextOptions
  13. struct OfflineAudioContextOptions {
  14. WebIDL::UnsignedLong number_of_channels { 1 };
  15. WebIDL::UnsignedLong length {};
  16. float sample_rate {};
  17. };
  18. // https://webaudio.github.io/web-audio-api/#OfflineAudioContext
  19. class OfflineAudioContext final : public BaseAudioContext {
  20. WEB_PLATFORM_OBJECT(OfflineAudioContext, BaseAudioContext);
  21. JS_DECLARE_ALLOCATOR(OfflineAudioContext);
  22. public:
  23. static WebIDL::ExceptionOr<JS::NonnullGCPtr<OfflineAudioContext>> construct_impl(JS::Realm&, OfflineAudioContextOptions const&);
  24. static WebIDL::ExceptionOr<JS::NonnullGCPtr<OfflineAudioContext>> construct_impl(JS::Realm&,
  25. WebIDL::UnsignedLong number_of_channels, WebIDL::UnsignedLong length, float sample_rate);
  26. virtual ~OfflineAudioContext() override;
  27. WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Promise>> start_rendering();
  28. WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Promise>> resume();
  29. WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Promise>> suspend(double suspend_time);
  30. WebIDL::UnsignedLong length() const;
  31. JS::GCPtr<WebIDL::CallbackType> oncomplete();
  32. void set_oncomplete(JS::GCPtr<WebIDL::CallbackType>);
  33. private:
  34. OfflineAudioContext(JS::Realm&, OfflineAudioContextOptions const&);
  35. OfflineAudioContext(JS::Realm&, WebIDL::UnsignedLong number_of_channels, WebIDL::UnsignedLong length, float sample_rate);
  36. virtual void initialize(JS::Realm&) override;
  37. virtual void visit_edges(Cell::Visitor&) override;
  38. WebIDL::UnsignedLong m_length {};
  39. };
  40. }