Go-based FM stereo transmitter with RDS, Windows-first and cross-platform
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

86 行
1.9KB

  1. package output
  2. import (
  3. "context"
  4. "sync"
  5. )
  6. // DummyBackend keeps track of the latest frame without writing anywhere. Useful for unit testing.
  7. type DummyBackend struct {
  8. mu sync.Mutex
  9. info BackendInfo
  10. cfg BackendConfig
  11. closed bool
  12. total uint64
  13. lastFrame CompositeFrame
  14. }
  15. // NewDummyBackend constructs a lean backend that records the last frame seen.
  16. func NewDummyBackend(name string) *DummyBackend {
  17. return &DummyBackend{
  18. info: BackendInfo{
  19. Name: name,
  20. Description: "in-memory dummy backend",
  21. Capabilities: BackendCapabilities{
  22. SupportsComposite: true,
  23. FixedRate: false,
  24. MaxSamplesPerWrite: 0,
  25. },
  26. },
  27. }
  28. }
  29. // Configure stores the config values.
  30. func (db *DummyBackend) Configure(_ context.Context, cfg BackendConfig) error {
  31. db.mu.Lock()
  32. defer db.mu.Unlock()
  33. db.cfg = cfg
  34. return nil
  35. }
  36. // Write captures the most recent frame and updates the sample count.
  37. func (db *DummyBackend) Write(_ context.Context, frame *CompositeFrame) (int, error) {
  38. db.mu.Lock()
  39. defer db.mu.Unlock()
  40. if frame == nil {
  41. return 0, nil
  42. }
  43. db.lastFrame = *frame
  44. db.total += uint64(len(frame.Samples))
  45. return len(frame.Samples), nil
  46. }
  47. // Flush is a no-op for the dummy backend.
  48. func (db *DummyBackend) Flush(_ context.Context) error {
  49. return nil
  50. }
  51. // Close marks the backend unusable.
  52. func (db *DummyBackend) Close(_ context.Context) error {
  53. db.mu.Lock()
  54. defer db.mu.Unlock()
  55. db.closed = true
  56. return nil
  57. }
  58. // Info returns the backend descriptors.
  59. func (db *DummyBackend) Info() BackendInfo {
  60. db.mu.Lock()
  61. defer db.mu.Unlock()
  62. return db.info
  63. }
  64. // TotalSamples reports how many samples have been written.
  65. func (db *DummyBackend) TotalSamples() uint64 {
  66. db.mu.Lock()
  67. defer db.mu.Unlock()
  68. return db.total
  69. }
  70. // LastFrame exposes a snapshot of the last frame written.
  71. func (db *DummyBackend) LastFrame() CompositeFrame {
  72. db.mu.Lock()
  73. defer db.mu.Unlock()
  74. return db.lastFrame
  75. }