video_encoder.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #ifndef VIDEO_CODECS_VIDEO_ENCODER_H_
  2. #define VIDEO_CODECS_VIDEO_ENCODER_H_
  3. #include "precompile.h"
  4. #ifdef __cplusplus
  5. #ifdef _STDINT_H
  6. #undef _STDINT_H
  7. #endif
  8. #include "stdint.h"
  9. #ifndef INT64_C
  10. #define INT64_C(c) (c ## LL)
  11. #define UINT64_C(c) (c ## ULL)
  12. #endif
  13. extern "C" {
  14. #endif
  15. #include "../video_common/ffmpeg_api_adapter.h"
  16. #include "x264.h"
  17. #ifdef __cplusplus
  18. }
  19. #endif /* end of __cplusplus */
  20. #include "../videoutil.h"
  21. #include "video_encoder_defines.h"
  22. #define FAILED_VALUE -1
  23. #define SUCCESS_VALUE 0
  24. namespace video_coding {
  25. typedef struct _QpThresholds {
  26. int low;
  27. int high;
  28. }QpThresholds;
  29. typedef struct _EncoderInfo {
  30. // If this field is true, the encoder uses hardware support and different
  31. // thresholds will be used in CPU adaptation.
  32. bool is_hardware_accelerated;
  33. QpThresholds thresholds;
  34. }EncoderInfo;
  35. typedef struct _VideoEncoder VideoEncoder;
  36. VideoEncoder *video_encoder_new();
  37. void video_encoder_destroy(VideoEncoder *obj);
  38. // Initialize the encoder with the information from the codecSettings
  39. //
  40. // Input:
  41. // - codec_settings : Codec settings
  42. // - max_payload_size : The maximum size each payload is allowed
  43. // to have. Usually MTU - overhead.
  44. //
  45. // Return value : Set bit rate if OK
  46. // <0 - Errors
  47. int32_t video_encoder_init_encode(VideoEncoder *obj, const VideoEncoderConfig* codec_settings,
  48. size_t max_payload_size);
  49. // Free encoder memory.
  50. // Return value : 0 if OK, < 0 otherwise.
  51. int32_t video_encoder_release(VideoEncoder *obj);
  52. // Encode an I420 image (as a part of a video stream). The encoded image
  53. // will be returned to the user through the encode complete callback.
  54. //
  55. // Input:
  56. // - frame : Image to be encoded
  57. // - frame_types : Frame type to be generated by the encoder.
  58. //
  59. // Return value : 0 if OK
  60. // <0 - Errors
  61. EncodedImage *video_encoder_encode(VideoEncoder *obj, unsigned pt, const video_frame *frame, int key_frame);
  62. /*bitrate:目标带宽,单位:kbps */
  63. int32_t video_encoder_set_rates(VideoEncoder *obj, uint32_t bitrate, uint32_t framerate);
  64. // Returns meta-data about the encoder, such as implementation name.
  65. // The output of this method may change during runtime. For instance if a
  66. // hardware encoder fails, it may fall back to doing software encoding using
  67. // an implementation with different characteristics.
  68. int32_t video_encoder_get_encoder_info(VideoEncoder *obj, EncoderInfo *info);
  69. }
  70. #endif // API_VIDEO_CODECS_VIDEO_ENCODER_H_