Guest User

Untitled

a guest
Aug 15th, 2026
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.96 KB | None | 0 0
  1. --- a/libffabi/src/ffabi.c 2026-08-14 21:05:19.511652228 -0600
  2. +++ b/libffabi/src/ffabi.c 2026-08-14 21:04:32.531358307 -0600
  3. @@ -531,90 +531,149 @@
  4. {
  5. char* exinfo;
  6. size_t len;
  7. - unsigned int count_ch_layouts_in = 0;
  8. + int count_ch_layouts_in = 0;
  9. unsigned int count_ch_layouts_out = 0;
  10. - uint64_t* channel_layouts;
  11. + uint64_t* channel_layouts;
  12. + const AVChannelLayout* ch_layouts = NULL;
  13. unsigned int i;
  14. + int ret;
  15.  
  16. len = strlen(codec->name);
  17. if (len >= FFM_CODEC_INFO_NAME_MAX_LENGTH) return -1;
  18.  
  19. - if (NULL != codec->ch_layouts) {
  20. - while (0 != codec->ch_layouts[count_ch_layouts_in].nb_channels)
  21. - {
  22. - count_ch_layouts_in++;
  23. - }
  24. - }
  25. + ret = avcodec_get_supported_config(
  26. + NULL, codec, AV_CODEC_CONFIG_CHANNEL_LAYOUT, 0,
  27. + (const void**)&ch_layouts, &count_ch_layouts_in
  28. + );
  29. +
  30. + if (ret < 0) return -1;
  31. +
  32. + exinfo = (char*)ffabi_memalign(
  33. + sizeof(uint64_t),
  34. + FFM_CODEC_INFO_NAME_MAX_LENGTH +
  35. + FFM_CODEC_INFO_EXMARK_LENGTH +
  36. + ((count_ch_layouts_in + 1) * sizeof(uint64_t))
  37. + );
  38.  
  39. - exinfo = (char*)ffabi_memalign(sizeof(uint64_t), (FFM_CODEC_INFO_NAME_MAX_LENGTH + FFM_CODEC_INFO_EXMARK_LENGTH + ((count_ch_layouts_in+1)*sizeof(uint64_t))));
  40. if (NULL == exinfo) return -1;
  41.  
  42. memcpy(exinfo, codec->name, len + 1);
  43. - memcpy(exinfo + FFM_CODEC_INFO_NAME_MAX_LENGTH, FFM_CODEC_INFO_EXMARK_MAGIC, FFM_CODEC_INFO_EXMARK_LENGTH);
  44. - channel_layouts = (uint64_t*)(exinfo + FFM_CODEC_INFO_NAME_MAX_LENGTH + FFM_CODEC_INFO_EXMARK_LENGTH);
  45. + memcpy(exinfo + FFM_CODEC_INFO_NAME_MAX_LENGTH,
  46. + FFM_CODEC_INFO_EXMARK_MAGIC,
  47. + FFM_CODEC_INFO_EXMARK_LENGTH);
  48. +
  49. + channel_layouts = (uint64_t*)(
  50. + exinfo +
  51. + FFM_CODEC_INFO_NAME_MAX_LENGTH +
  52. + FFM_CODEC_INFO_EXMARK_LENGTH
  53. + );
  54.  
  55. info->name = exinfo;
  56. info->channel_layouts = channel_layouts;
  57.  
  58. - for (i = 0; i < count_ch_layouts_in; i++)
  59. - {
  60. - if (AV_CHANNEL_ORDER_NATIVE != codec->ch_layouts[i].order) continue;
  61. - channel_layouts[count_ch_layouts_out++] = codec->ch_layouts[i].u.mask;
  62. + for (i = 0; i < (unsigned int)count_ch_layouts_in; i++) {
  63. + if (AV_CHANNEL_ORDER_NATIVE != ch_layouts[i].order)
  64. + continue;
  65. +
  66. + channel_layouts[count_ch_layouts_out++] =
  67. + ch_layouts[i].u.mask;
  68. }
  69. +
  70. channel_layouts[count_ch_layouts_out] = 0;
  71.  
  72. return 0;
  73. }
  74. #endif
  75.  
  76. -int __cdecl ffm_audio_get_codec_information(FFM_CodecInfo* info, const char* name, int encode)
  77. +int __cdecl ffm_audio_get_codec_information(
  78. + FFM_CodecInfo* info,
  79. + const char* name,
  80. + int encode)
  81. {
  82. AVCodec* codec;
  83. + const int* sample_rates = NULL;
  84. + const enum AVSampleFormat* sample_fmts = NULL;
  85. +#ifndef FFABI_HAVE_OLD_CHANNEL_LAYOUT
  86. + const AVChannelLayout* ch_layouts = NULL;
  87. +#endif
  88. + int num_sample_rates = 0;
  89. + int num_sample_fmts = 0;
  90. +#ifndef FFABI_HAVE_OLD_CHANNEL_LAYOUT
  91. + int num_ch_layouts = 0;
  92. +#endif
  93. + int ret;
  94. int i;
  95.  
  96. memset(info, 0, sizeof(*info));
  97.  
  98. if (encode) {
  99. - codec = (AVCodec*) avcodec_find_encoder_by_name(name);
  100. + codec = (AVCodec*)avcodec_find_encoder_by_name(name);
  101. } else {
  102. - codec = (AVCodec*) avcodec_find_decoder_by_name(name);
  103. + codec = (AVCodec*)avcodec_find_decoder_by_name(name);
  104. }
  105.  
  106. - if (!codec) {
  107. + if (!codec)
  108. return ffmerr(1, encode);
  109. - }
  110.  
  111. info->name = codec->name;
  112. info->long_name = codec->long_name;
  113. - info->sample_rates = codec->supported_samplerates;
  114. +
  115. + ret = avcodec_get_supported_config(
  116. + NULL, codec, AV_CODEC_CONFIG_SAMPLE_RATE, 0,
  117. + (const void**)&sample_rates, &num_sample_rates
  118. + );
  119. +
  120. + if (ret < 0)
  121. + return ffmerr(2, 0);
  122. +
  123. + info->sample_rates = sample_rates;
  124. +
  125. #ifdef FFABI_HAVE_OLD_CHANNEL_LAYOUT
  126. info->channel_layouts = codec->channel_layouts;
  127. #else
  128. - if (NULL == codec->ch_layouts) {
  129. + ret = avcodec_get_supported_config(
  130. + NULL, codec, AV_CODEC_CONFIG_CHANNEL_LAYOUT, 0,
  131. + (const void**)&ch_layouts, &num_ch_layouts
  132. + );
  133. +
  134. + if (ret < 0)
  135. + return ffmerr(2, 0);
  136. +
  137. + if (NULL == ch_layouts) {
  138. info->channel_layouts = NULL;
  139. } else {
  140. - if (set_codec_info_extended(info, codec)) {
  141. + if (set_codec_info_extended(info, codec))
  142. return ffmerr(2, 0);
  143. - }
  144. }
  145. #endif
  146. +
  147. info->id = codec->id;
  148. info->capabilities = codec->capabilities;
  149. +
  150. if (codec->profiles) {
  151. - for (i=0;i<32;i++) {
  152. - if (codec->profiles[i].profile==AV_PROFILE_UNKNOWN)
  153. + for (i = 0; i < 32; i++) {
  154. + if (codec->profiles[i].profile == AV_PROFILE_UNKNOWN)
  155. break;
  156. - info->profiles_names[i]=codec->profiles[i].name;
  157. - info->profiles_values[i]=codec->profiles[i].profile;
  158. - info->profiles_count = i+1;
  159. +
  160. + info->profiles_names[i] = codec->profiles[i].name;
  161. + info->profiles_values[i] = codec->profiles[i].profile;
  162. + info->profiles_count = i + 1;
  163. }
  164. }
  165. - if (codec->sample_fmts) {
  166. - for (i=0;i<16;i++) {
  167. - if (codec->sample_fmts[i]==AV_SAMPLE_FMT_NONE)
  168. - break;
  169. - info->sample_formats[i]=(uint8_t)back_translate_sample_fmt(codec->sample_fmts[i]);
  170. - info->sample_formats_count = i+1;
  171. +
  172. + ret = avcodec_get_supported_config(
  173. + NULL, codec, AV_CODEC_CONFIG_SAMPLE_FORMAT, 0,
  174. + (const void**)&sample_fmts, &num_sample_fmts
  175. + );
  176. +
  177. + if (ret < 0)
  178. + return ffmerr(2, 0);
  179. +
  180. + if (sample_fmts) {
  181. + for (i = 0; i < num_sample_fmts && i < 16; i++) {
  182. + info->sample_formats[i] =
  183. + (uint8_t)back_translate_sample_fmt(sample_fmts[i]);
  184. + info->sample_formats_count = i + 1;
  185. }
  186. }
  187.  
Advertisement
Add Comment
Please, Sign In to add comment