android_audiotrack.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*****************************************************************************
  2. * android_audiotrack.h
  3. *****************************************************************************
  4. *
  5. * Copyright (c) 2013 Bilibili
  6. * copyright (c) 2013 Zhang Rui <bbcallen@gmail.com>
  7. *
  8. * This file is part of ijkPlayer.
  9. *
  10. * ijkPlayer is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation; either
  13. * version 2.1 of the License, or (at your option) any later version.
  14. *
  15. * ijkPlayer is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with ijkPlayer; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. */
  24. #ifndef IJKSDL_ANDROID__ANDROID_AUDIOTRACK_H
  25. #define IJKSDL_ANDROID__ANDROID_AUDIOTRACK_H
  26. #include <stdint.h>
  27. #include <jni.h>
  28. #include "../ijksdl_audio.h"
  29. #include "../ijksdl_aout.h"
  30. #define AUDIOTRACK_PLAYBACK_MAXSPEED (2)
  31. typedef struct SDL_Android_AudioTrack_Spec {
  32. enum StreamType {
  33. STREAM_VOICE_CALL = 0,
  34. STREAM_SYSTEM = 1,
  35. STREAM_RING = 2,
  36. STREAM_MUSIC = 3,
  37. STREAM_ALARM = 4,
  38. STREAM_NOTIFICATION = 5,
  39. } stream_type;
  40. int sample_rate_in_hz;
  41. enum ChannelConfig {
  42. CHANNEL_OUT_INVALID = 0x0,
  43. CHANNEL_OUT_DEFAULT = 0x1, /* f-l */
  44. CHANNEL_OUT_MONO = 0x4, /* f-l, f-r */
  45. CHANNEL_OUT_STEREO = 0xc, /* f-l, f-r, b-l, b-r */
  46. CHANNEL_OUT_QUAD = 0xcc, /* f-l, f-r, b-l, b-r */
  47. CHANNEL_OUT_SURROUND = 0x41c, /* f-l, f-r, f-c, b-c */
  48. CHANNEL_OUT_5POINT1 = 0xfc, /* f-l, f-r, b-l, b-r, f-c, low */
  49. CHANNEL_OUT_7POINT1 = 0x3fc, /* f-l, f-r, b-l, b-r, f-c, low, f-lc, f-rc */
  50. CHANNEL_OUT_FRONT_LEFT = 0x4,
  51. CHANNEL_OUT_FRONT_RIGHT = 0x8,
  52. CHANNEL_OUT_BACK_LEFT = 0x40,
  53. CHANNEL_OUT_BACK_RIGHT = 0x80,
  54. CHANNEL_OUT_FRONT_CENTER = 0x10,
  55. CHANNEL_OUT_LOW_FREQUENCY = 0x20,
  56. CHANNEL_OUT_FRONT_LEFT_OF_CENTER = 0x100,
  57. CHANNEL_OUT_FRONT_RIGHT_OF_CENTER = 0x200,
  58. CHANNEL_OUT_BACK_CENTER = 0x400,
  59. } channel_config;
  60. enum AudioFormat {
  61. ENCODING_INVALID = 0,
  62. ENCODING_DEFAULT = 1,
  63. ENCODING_PCM_16BIT = 2, // signed, guaranteed to be supported by devices.
  64. ENCODING_PCM_8BIT = 3, // unsigned, not guaranteed to be supported by devices.
  65. ENCODING_PCM_FLOAT = 4, // single-precision floating-point per sample
  66. } audio_format;
  67. int buffer_size_in_bytes;
  68. enum Mode {
  69. MODE_STATIC = 0,
  70. MODE_STREAM = 1,
  71. } mode;
  72. enum WriteMode {
  73. WRITE_BLOCKING = 0,
  74. WRITE_NON_BLOCKING = 1,
  75. } write_mode; // not used
  76. // extra field
  77. int sdl_samples;
  78. } SDL_Android_AudioTrack_Spec;
  79. typedef struct SDL_Android_AudioTrack SDL_Android_AudioTrack;
  80. SDL_Android_AudioTrack *SDL_Android_AudioTrack_new_from_spec(JNIEnv *env, SDL_Android_AudioTrack_Spec *spec);
  81. SDL_Android_AudioTrack *SDL_Android_AudioTrack_new_from_sdl_spec(JNIEnv *env, const SDL_AudioSpec *sdl_spec);
  82. void SDL_Android_AudioTrack_free(JNIEnv *env, SDL_Android_AudioTrack* atrack);
  83. void SDL_Android_AudioTrack_get_target_spec(SDL_Android_AudioTrack* atrack, SDL_AudioSpec *spec);
  84. int SDL_Android_AudioTrack_get_min_buffer_size(SDL_Android_AudioTrack* atrack);
  85. int audiotrack_get_native_output_sample_rate(JNIEnv *env/* = NULL */);
  86. void SDL_Android_AudioTrack_play(JNIEnv *env, SDL_Android_AudioTrack *atrack);
  87. void SDL_Android_AudioTrack_pause(JNIEnv *env, SDL_Android_AudioTrack *atrack);
  88. void SDL_Android_AudioTrack_flush(JNIEnv *env, SDL_Android_AudioTrack *atrack);
  89. void SDL_Android_AudioTrack_set_volume(JNIEnv *env, SDL_Android_AudioTrack *atrack, float left_volume, float right_volume);
  90. void SDL_Android_AudioTrack_stop(JNIEnv *env, SDL_Android_AudioTrack *atrack);
  91. void SDL_Android_AudioTrack_release(JNIEnv *env, SDL_Android_AudioTrack *atrack);
  92. int SDL_Android_AudioTrack_write(JNIEnv *env, SDL_Android_AudioTrack *atrack, uint8_t *data, int size_in_byte);
  93. int SDL_Android_AudioTrack_getAudioSessionId(JNIEnv *env, SDL_Android_AudioTrack *atrack);
  94. void SDL_Android_AudioTrack_setSpeed(JNIEnv *env, SDL_Android_AudioTrack *atrack, float speed);
  95. #endif