vidtv_encoder.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Vidtv serves as a reference DVB driver and helps validate the existing APIs
  4. * in the media subsystem. It can also aid developers working on userspace
  5. * applications.
  6. *
  7. * This file contains a generic encoder type that can provide data for a stream
  8. *
  9. * Copyright (C) 2020 Daniel W. S. Almeida
  10. */
  11. #ifndef VIDTV_ENCODER_H
  12. #define VIDTV_ENCODER_H
  13. #include <linux/types.h>
  14. enum vidtv_encoder_id {
  15. /* add IDs here when implementing new encoders */
  16. S302M,
  17. };
  18. struct vidtv_access_unit {
  19. u32 num_samples;
  20. u64 pts;
  21. u64 dts;
  22. u32 nbytes;
  23. u32 offset;
  24. struct vidtv_access_unit *next;
  25. };
  26. /* Some musical notes, used by a tone generator. Values are in Hz */
  27. enum musical_notes {
  28. NOTE_SILENT = 0,
  29. NOTE_C_2 = 65,
  30. NOTE_CS_2 = 69,
  31. NOTE_D_2 = 73,
  32. NOTE_DS_2 = 78,
  33. NOTE_E_2 = 82,
  34. NOTE_F_2 = 87,
  35. NOTE_FS_2 = 93,
  36. NOTE_G_2 = 98,
  37. NOTE_GS_2 = 104,
  38. NOTE_A_2 = 110,
  39. NOTE_AS_2 = 117,
  40. NOTE_B_2 = 123,
  41. NOTE_C_3 = 131,
  42. NOTE_CS_3 = 139,
  43. NOTE_D_3 = 147,
  44. NOTE_DS_3 = 156,
  45. NOTE_E_3 = 165,
  46. NOTE_F_3 = 175,
  47. NOTE_FS_3 = 185,
  48. NOTE_G_3 = 196,
  49. NOTE_GS_3 = 208,
  50. NOTE_A_3 = 220,
  51. NOTE_AS_3 = 233,
  52. NOTE_B_3 = 247,
  53. NOTE_C_4 = 262,
  54. NOTE_CS_4 = 277,
  55. NOTE_D_4 = 294,
  56. NOTE_DS_4 = 311,
  57. NOTE_E_4 = 330,
  58. NOTE_F_4 = 349,
  59. NOTE_FS_4 = 370,
  60. NOTE_G_4 = 392,
  61. NOTE_GS_4 = 415,
  62. NOTE_A_4 = 440,
  63. NOTE_AS_4 = 466,
  64. NOTE_B_4 = 494,
  65. NOTE_C_5 = 523,
  66. NOTE_CS_5 = 554,
  67. NOTE_D_5 = 587,
  68. NOTE_DS_5 = 622,
  69. NOTE_E_5 = 659,
  70. NOTE_F_5 = 698,
  71. NOTE_FS_5 = 740,
  72. NOTE_G_5 = 784,
  73. NOTE_GS_5 = 831,
  74. NOTE_A_5 = 880,
  75. NOTE_AS_5 = 932,
  76. NOTE_B_5 = 988,
  77. NOTE_C_6 = 1047,
  78. NOTE_CS_6 = 1109,
  79. NOTE_D_6 = 1175,
  80. NOTE_DS_6 = 1245,
  81. NOTE_E_6 = 1319,
  82. NOTE_F_6 = 1397,
  83. NOTE_FS_6 = 1480,
  84. NOTE_G_6 = 1568,
  85. NOTE_GS_6 = 1661,
  86. NOTE_A_6 = 1760,
  87. NOTE_AS_6 = 1865,
  88. NOTE_B_6 = 1976,
  89. NOTE_C_7 = 2093
  90. };
  91. /**
  92. * struct vidtv_encoder - A generic encoder type.
  93. * @id: So we can cast to a concrete implementation when needed.
  94. * @name: Usually the same as the stream name.
  95. * @encoder_buf: The encoder internal buffer for the access units.
  96. * @encoder_buf_sz: The encoder buffer size, in bytes
  97. * @encoder_buf_offset: Our byte position in the encoder buffer.
  98. * @sample_count: How many samples we have encoded in total.
  99. * @access_units: encoder payload units, used for clock references
  100. * @src_buf: The source of raw data to be encoded, encoder might set a
  101. * default if null.
  102. * @src_buf_sz: size of @src_buf.
  103. * @src_buf_offset: Our position in the source buffer.
  104. * @is_video_encoder: Whether this a video encoder (as opposed to audio)
  105. * @ctx: Encoder-specific state.
  106. * @stream_id: Examples: Audio streams (0xc0-0xdf), Video streams
  107. * (0xe0-0xef).
  108. * @es_pid: The TS PID to use for the elementary stream in this encoder.
  109. * @encode: Prepare enough AUs for the given amount of time.
  110. * @clear: Clear the encoder output.
  111. * @sync: Attempt to synchronize with this encoder.
  112. * @sampling_rate_hz: The sampling rate (or fps, if video) used.
  113. * @last_sample_cb: Called when the encoder runs out of data.This is
  114. * so the source can read data in a
  115. * piecemeal fashion instead of having to
  116. * provide it all at once.
  117. * @destroy: Destroy this encoder, freeing allocated resources.
  118. * @next: Next in the chain
  119. */
  120. struct vidtv_encoder {
  121. enum vidtv_encoder_id id;
  122. char *name;
  123. u8 *encoder_buf;
  124. u32 encoder_buf_sz;
  125. u32 encoder_buf_offset;
  126. u64 sample_count;
  127. struct vidtv_access_unit *access_units;
  128. void *src_buf;
  129. u32 src_buf_sz;
  130. u32 src_buf_offset;
  131. bool is_video_encoder;
  132. void *ctx;
  133. __be16 stream_id;
  134. __be16 es_pid;
  135. void *(*encode)(struct vidtv_encoder *e);
  136. u32 (*clear)(struct vidtv_encoder *e);
  137. struct vidtv_encoder *sync;
  138. u32 sampling_rate_hz;
  139. void (*last_sample_cb)(u32 sample_no);
  140. void (*destroy)(struct vidtv_encoder *e);
  141. struct vidtv_encoder *next;
  142. };
  143. #endif /* VIDTV_ENCODER_H */