libtheora_info.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /********************************************************************
  2. * *
  3. * THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *
  4. * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
  5. * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
  6. * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
  7. * *
  8. * THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2010 *
  9. * by the Xiph.Org Foundation and contributors http://www.xiph.org/ *
  10. * *
  11. ********************************************************************
  12. function: example of querying various library parameters.
  13. last mod: $Id$
  14. ********************************************************************/
  15. #ifdef HAVE_CONFIG_H
  16. # include <config.h>
  17. #endif
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include "theora/theoraenc.h"
  21. /* Print the library's bitstream version number
  22. This is the highest supported bitstream version number,
  23. not the version number of the implementation itself. */
  24. int print_version(void)
  25. {
  26. unsigned version = th_version_number();
  27. fprintf(stdout, "Bitstream: %d.%d.%d (0x%06X)\n",
  28. (version >> 16) & 0xff, (version >> 8) & 0xff, (version) & 0xff,
  29. version);
  30. return 0;
  31. }
  32. /* Print the library's own version string
  33. This is generally the same at the vendor string embedded
  34. in encoded files. */
  35. int print_version_string(void)
  36. {
  37. const char *version = th_version_string();
  38. if (version == NULL) {
  39. fprintf(stderr, "Error querying libtheora version string.\n");
  40. return -1;
  41. }
  42. fprintf(stdout, "Version: %s\n", version);
  43. return 0;
  44. }
  45. /* Generate a dummy encoder context for use in th_encode_ctl queries */
  46. th_enc_ctx *dummy_encode_ctx(void)
  47. {
  48. th_enc_ctx *ctx;
  49. th_info info;
  50. /* set the minimal video parameters */
  51. th_info_init(&info);
  52. info.frame_width=320;
  53. info.frame_height=240;
  54. info.fps_numerator=1;
  55. info.fps_denominator=1;
  56. /* allocate and initialize a context object */
  57. ctx = th_encode_alloc(&info);
  58. if (ctx == NULL) {
  59. fprintf(stderr, "Error allocating encoder context.\n");
  60. }
  61. /* clear the info struct */
  62. th_info_clear(&info);
  63. return ctx;
  64. }
  65. /* Query the current and maximum values for the 'speed level' setting.
  66. This can be used to ask the encoder to trade off encoding quality
  67. vs. performance cost, for example to adapt to realtime constraints. */
  68. int check_speed_level(th_enc_ctx *ctx, int *current, int *max)
  69. {
  70. int ret;
  71. /* query the current speed level */
  72. ret = th_encode_ctl(ctx, TH_ENCCTL_GET_SPLEVEL, current, sizeof(int));
  73. if (ret) {
  74. fprintf(stderr, "Error %d getting current speed level.\n", ret);
  75. return ret;
  76. }
  77. /* query the maximum speed level, which varies by encoder version */
  78. ret = th_encode_ctl(ctx, TH_ENCCTL_GET_SPLEVEL_MAX, max, sizeof(int));
  79. if (ret) {
  80. fprintf(stderr, "Error %d getting max speed level.\n", ret);
  81. return ret;
  82. }
  83. return 0;
  84. }
  85. /* Print the current and maximum speed level settings */
  86. int print_speed_level(th_enc_ctx *ctx)
  87. {
  88. int current = -1;
  89. int max = -1;
  90. int ret;
  91. ret = check_speed_level(ctx, &current, &max);
  92. if (ret == 0) {
  93. fprintf(stdout, "Default speed level: %d\n", current);
  94. fprintf(stdout, "Maximum speed level: %d\n", max);
  95. }
  96. return ret;
  97. }
  98. int main(int argc, char **argv) {
  99. th_enc_ctx *ctx;
  100. /* print versioning */
  101. print_version_string();
  102. print_version();
  103. /* allocate a generic context for queries that require it */
  104. ctx = dummy_encode_ctx();
  105. if (ctx != NULL) {
  106. /* dump the speed level setting */
  107. print_speed_level(ctx);
  108. /* clean up */
  109. th_encode_free(ctx);
  110. }
  111. return 0;
  112. }