Skip to content

Commit

Permalink
allow specyfing width, height and profile
Browse files Browse the repository at this point in the history
- folow HVD interface change with optional decoder config

Related to bmegli/hardware-video-decoder#11
Related to bmegli/hardware-video-decoder#12
  • Loading branch information
bmegli committed Jan 12, 2020
1 parent 0b80e18 commit 9d5f1da
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
16 changes: 14 additions & 2 deletions examples/nhvd_receive_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ const char *PIXEL_FORMAT="bgr0"; //NULL for default (NV12) or pixel format e.g.
//the pixel format that you want to receive data in
//this has to be supported by hardware
//here "bgr0" for easy integration with Unity
const int WIDTH=0; //0 to not specify, needed by some codecs
const int HEIGHT=0; //0 to not specify, needed by some codecs
const int PROFILE=0; //0 to leave as FF_PROFILE_UNKNOWN
//for list of profiles see:
//https://ffmpeg.org/doxygen/3.4/avcodec_8h.html#ab424d258655424e4b1690e2ab6fcfc66

//network configuration
const char *IP=NULL; //listen on or NULL (listen on any)
Expand All @@ -44,7 +49,7 @@ const int SLEEP_US = 1000000/30;

int main(int argc, char **argv)
{
nhvd_hw_config hw_config= {HARDWARE, CODEC, DEVICE, PIXEL_FORMAT};
nhvd_hw_config hw_config= {HARDWARE, CODEC, DEVICE, PIXEL_FORMAT, WIDTH, HEIGHT, PROFILE};
nhvd_net_config net_config= {IP, PORT, TIMEOUT_MS};

if(process_user_input(argc, argv, &hw_config, &net_config) != 0)
Expand Down Expand Up @@ -104,7 +109,7 @@ int process_user_input(int argc, char **argv, nhvd_hw_config *hw_config, nhvd_ne
{
if(argc < 4)
{
fprintf(stderr, "Usage: %s <port> <hardware> <codec> [device]\n\n", argv[0]);
fprintf(stderr, "Usage: %s <port> <hardware> <codec> [device] [width] [height] [profile]\n\n", argv[0]);
fprintf(stderr, "examples: \n");
fprintf(stderr, "%s 9766 vaapi h264 \n", argv[0]);
fprintf(stderr, "%s 9766 vdpau h264 \n", argv[0]);
Expand All @@ -113,6 +118,9 @@ int process_user_input(int argc, char **argv, nhvd_hw_config *hw_config, nhvd_ne
fprintf(stderr, "%s 9766 dxva2 h264 \n", argv[0]);
fprintf(stderr, "%s 9766 d3d11va h264 \n", argv[0]);
fprintf(stderr, "%s 9766 videotoolbox h264 \n", argv[0]);
fprintf(stderr, "%s 9766 vaapi hevc /dev/dri/renderD128 640 360 1\n", argv[0]);
fprintf(stderr, "%s 9766 vaapi hevc /dev/dri/renderD128 848 480 2\n", argv[0]);

return 1;
}

Expand All @@ -121,5 +129,9 @@ int process_user_input(int argc, char **argv, nhvd_hw_config *hw_config, nhvd_ne
hw_config->codec = argv[3];
hw_config->device = argv[4]; //NULL or device, both are ok

if(argc >= 6) hw_config->width = atoi(argv[5]);
if(argc >= 7) hw_config->height = atoi(argv[6]);
if(argc >= 8) hw_config->profile = atoi(argv[7]);

return 0;
}
2 changes: 1 addition & 1 deletion hardware-video-decoder
3 changes: 2 additions & 1 deletion nhvd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ struct nhvd
struct nhvd *nhvd_init(const nhvd_net_config *net_config,const nhvd_hw_config *hw_config)
{
mlsp_config mlsp_cfg={net_config->ip, net_config->port, net_config->timeout_ms};
hvd_config hvd_cfg={hw_config->hardware, hw_config->codec, hw_config->device, hw_config->pixel_format};
hvd_config hvd_cfg={hw_config->hardware, hw_config->codec, hw_config->device,
hw_config->pixel_format, hw_config->width, hw_config->height, hw_config->profile};

nhvd *n=new nhvd();

Expand Down
3 changes: 3 additions & 0 deletions nhvd.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ struct nhvd_hw_config
const char *codec; //!< codec name, e.g. "h264", "vp8"
const char *device; //!< NULL/empty string or device, e.g. "/dev/dri/renderD128"
const char *pixel_format; //!< NULL for default or format, e.g. "rgb0", "bgr0", "nv12", "yuv420p"
int width; //!< 0 to not specify, needed by some codecs
int height; //!< 0 to not specify, needed by some codecs
int profile; //!< 0 to leave as FF_PROFILE_UNKNOWN or profile e.g. FF_PROFILE_HEVC_MAIN, ...
};

struct nhvd_net_config
Expand Down

0 comments on commit 9d5f1da

Please sign in to comment.