/usr/include/guvcview-2/libgviewencoder/gviewencoder.h is in libguvcview-dev 2.0.5+debian-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 | /*******************************************************************************#
# guvcview http://guvcview.sourceforge.net #
# #
# Paulo Assis <pj.assis@gmail.com> #
# Nobuhiro Iwamatsu <iwamatsu@nigauri.org> #
# Add UYVY color support(Macbook iSight) #
# Flemming Frandsen <dren.dk@gmail.com> #
# Add VU meter OSD #
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program; if not, write to the Free Software #
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #
# #
********************************************************************************/
/*******************************************************************************#
# #
# Encoder library #
# #
********************************************************************************/
#ifndef GVIEWENCODER_H
#define GVIEWENCODER_H
#include <features.h>
#include <inttypes.h>
#include <sys/types.h>
/*make sure we support c++*/
__BEGIN_DECLS
/*encoder modes*/
#define ENCODER_MODE_NONE (0)
#define ENCODER_MODE_RAW (1)
/*Muxer defs*/
#define ENCODER_MUX_MKV (0)
#define ENCODER_MUX_WEBM (1)
#define ENCODER_MUX_AVI (2)
/*Scheduler Modes*/
#define ENCODER_SCHED_LIN (0)
#define ENCODER_SCHED_EXP (1)
/*audio sample format*/
#ifndef GV_SAMPLE_TYPE_INT16
#define GV_SAMPLE_TYPE_INT16 (0) //interleaved
#define GV_SAMPLE_TYPE_FLOAT (1) //interleaved
#define GV_SAMPLE_TYPE_INT16P (2) //planar
#define GV_SAMPLE_TYPE_FLOATP (3) //planar
#endif
#define MAX_DELAYED_FRAMES 68 /*Maximum supported delayed frames*/
/*video buffer*/
typedef struct _video_buffer_t
{
uint8_t *frame; /*uncompressed*/
int frame_size;
int64_t timestamp;
int keyframe; /* 1-keyframe; 0-non keyframe (only for direct input)*/
int flag; /*VIDEO_BUFF_FREE | VIDEO_BUFF_USED*/
} video_buffer_t;
/*video codec properties*/
typedef struct _video_codec_t
{
int valid; //the encoding codec exists in libav
char compressor[5]; //fourcc - upper case
int mkv_4cc; //fourcc WORD value
char mkv_codec[25]; //mkv codecID
void *mkv_codecPriv; //mkv codec private data
char description[35]; //codec description
int pix_fmt; //codec input pixel format
int fps; // encoder frame rate (used for time base)
int bit_rate; //lavc default bit rate
int qmax; //lavc qmax
int qmin; //lavc qmin
int max_qdiff; //lavc qmin
int dia; //lavc dia_size
int pre_dia; //lavc pre_dia_size
int pre_me; //lavc pre_me
int me_pre_cmp; //lavc me_pre_cmp
int me_cmp; //lavc me_cmp
int me_sub_cmp; //lavc me_sub_cmp
int last_pred; //lavc last_predictor_count
int gop_size; //lavc gop_size
float qcompress; //lavc qcompress
float qblur; //lavc qblur
int subq; //lavc subq
int framerefs; //lavc refs
int codec_id; //lavc codec_id
char codec_name[20]; //lavc codec_name
int mb_decision; //lavc mb_decision
int trellis; //lavc trellis quantization
int me_method; //lavc motion estimation method
int mpeg_quant; //lavc mpeg quantization
int max_b_frames; //lavc max b frames
int num_threads; //lavc num threads
int flags; //lavc flags
int monotonic_pts; //use monotonic pts instead of timestamp based
} video_codec_t;
/*audio codec properties*/
typedef struct _audio_codec_t
{
int valid; //the encoding codec exists in ffmpeg
int bits; //bits per sample (pcm only)
int monotonic_pts;
uint16_t avi_4cc; //fourcc value (4 bytes)
char mkv_codec[25]; //mkv codecID
char description[35]; //codec description
int bit_rate; //lavc default bit rate
int codec_id; //lavc codec_id
char codec_name[20]; //lavc codec name
int sample_format; //lavc sample format
int profile; //for AAC only
void *mkv_codpriv; //pointer for codec private data
int codpriv_size; //size in bytes of private data
int flags; //lavc flags
char name[5]; //common 4cc name (lowercase)
} audio_codec_t;
/*video*/
typedef struct _encoder_video_context_t
{
void *codec_data;
int monotonic_pts;
/*delayed frames handling*/
int write_df; /*index of delayed frame pts for write;*/
int read_df; /*index of delayed frame pts for read;*/
int64_t delayed_pts[MAX_DELAYED_FRAMES]; /*delayed frames pts*/
int flush_delayed_frames;
int flushed_buffers;
int flush_done;
uint8_t *priv_data;
uint8_t* tmpbuf;
int outbuf_size;
uint8_t* outbuf;
int outbuf_coded_size;
int64_t framecount;
int64_t pts;
int64_t dts;
int flags;
int duration;
} encoder_video_context_t;
/*Audio*/
typedef struct _encoder_audio_context_t
{
void *codec_data;
int avi_4cc;
int monotonic_pts;
/*delayed frames handling*/
int flush_delayed_frames;
int flushed_buffers;
int flush_done;
uint8_t *priv_data;
int outbuf_size;
uint8_t* outbuf;
int outbuf_coded_size;
int64_t pts;
int64_t dts;
int flags;
int duration;
} encoder_audio_context_t;
typedef struct _encoder_context_t
{
int muxer_id;
int input_format;
int video_codec_ind;
int audio_codec_ind;
int video_width;
int video_height;
int fps_num;
int fps_den;
int audio_channels;
int audio_samprate;
encoder_video_context_t *enc_video_ctx;
encoder_audio_context_t *enc_audio_ctx;
/*external h264 encoder data*/
int h264_pps_size;
uint8_t *h264_pps;
int h264_sps_size;
uint8_t *h264_sps;
} encoder_context_t;
/*
* set verbosity
* args:
* value - verbosity value
*
* asserts:
* none
*
* returns: none
*/
void encoder_set_verbosity(int value);
/*
* get valid video codec count
* args:
* none
*
* asserts:
* none
*
* returns: number of valid video codecs
*/
int encoder_get_valid_video_codecs();
/*
* get valid audio codec count
* args:
* none
*
* asserts:
* none
*
* returns: number of valid audio codecs
*/
int encoder_get_valid_audio_codecs();
/*
* sets the valid flag in the video codecs list
* args:
* none
*
* asserts:
* none
*
* returns: number of valid video codecs in list
*/
int encoder_set_valid_video_codec_list ();
/*
* sets the valid flag in the audio codecs list
* args:
* none
*
* asserts:
* none
*
* returns: number of valid audio codecs in list
*/
int encoder_set_valid_audio_codec_list ();
/*
* get video list codec description
* args:
* codec_ind - codec list index
*
* asserts:
* none
*
* returns: list codec entry or NULL if none
*/
const char *encoder_get_video_codec_description(int codec_ind);
/*
* get audio list codec description
* args:
* codec_ind - codec list index
*
* asserts:
* none
*
* returns: list codec entry or NULL if none
*/
const char *encoder_get_audio_codec_description(int codec_ind);
/*
* encoder initialization
* args:
* input_format - input v4l2 format (yuyv for encoding)
* video_codec_ind - video codec list index
* audio_codec_ind - audio codec list index
* muxer_id - file muxer:
* ENCODER_MUX_MKV; ENCODER_MUX_WEBM; ENCODER_MUX_AVI
* video_width - video frame width
* video_height - video frame height
* fps_num - fps numerator
* fps_den - fps denominator
* audio_channels- audio channels
* audio_samprate- audio sample rate
*
* asserts:
* none
*
* returns: pointer to encoder context (NULL on error)
*/
encoder_context_t *encoder_init(
int input_format,
int video_codec_ind,
int audio_codec_ind,
int muxer_id,
int video_width,
int video_height,
int fps_num,
int fps_den,
int audio_channels,
int audio_samprate);
/*
* initialization of the file muxer
* args:
* encoder_ctx - pointer to encoder context
* filename - video filename
*
* asserts:
* encoder_ctx is not null
*
* returns: none
*/
void encoder_muxer_init(encoder_context_t *encoder_ctx, const char *filename);
/*
* close the file muxer
* args:
* encoder_ctx - pointer to encoder context
*
* asserts:
* none
*
* returns: none
*/
void encoder_muxer_close(encoder_context_t *encoder_ctx);
/*
* get video list codec entry for codec index
* args:
* codec_ind - codec list index
*
* asserts:
* none
*
* returns: list codec entry or NULL if none
*/
video_codec_t *encoder_get_video_codec_defaults(int codec_ind);
/*
* get audio list codec entry for codec index
* args:
* codec_ind - codec list index
*
* asserts:
* none
*
* returns: audio list codec entry or NULL if none
*/
audio_codec_t *encoder_get_audio_codec_defaults(int codec_ind);
/*
* checks if the video codec index corresponds to VP8 or VP9 (webm) codec
* args:
* codec_ind - video codec list index
*
* asserts:
* none
*
* returns: 1 true; 0 false
*/
int encoder_check_webm_video_codec(int codec_ind);
/*
* get video codec list index for avi 4cc
* args:
* codec_4cc - codec 4cc
*
* asserts:
* none
*
* returns: codec index or -1 if error
*/
int encoder_get_video_codec_ind_4cc(const char *codec_4cc);
/*
* get video compressor (avi 4cc code)
* args:
* codec_ind - codec list index
*
* asserts:
* none
*
* returns: compressor codec entry or NULL if none
*/
const char *encoder_get_video_codec_4cc(int codec_ind);
/*
* get audio codec name
* args:
* codec_ind - codec list index
*
* asserts:
* none
*
* returns: codec name entry
*/
const char *encoder_get_audio_codec_name(int codec_ind);
/*
* get audio sample format max value
* args:
* none
*
* returns the maximum audio sample format value
*/
int encoder_get_max_audio_sample_fmt();
/*
* get audio codec list index for codec name
* args:
* codec_name - codec common name
*
* asserts:
* none
*
* returns: codec index or -1 if error
*/
int encoder_get_audio_codec_ind_name(const char *codec_name);
/*
* get the audio encoder frame size
* args:
* encoder_ctx - pointer to encoder context
*
* asserts:
* encoder_ctx is not null
*
* returns: audio encoder frame size
*/
int encoder_get_audio_frame_size(encoder_context_t *encoder_ctx);
/*
* get the audio encoder input sample format
* args:
* encoder_ctx - pointer to encoder context
*
* asserts:
* encoder_ctx is not null
*
* returns: audio encoder sample format
*/
int encoder_get_audio_sample_fmt(encoder_context_t *encoder_ctx);
/*
* get the video codec index for VP9 (webm) codec
* args:
* none
*
* asserts:
* none
*
* returns: index for VP9 codec or -1 if error
*/
int encoder_get_webm_video_codec_index();
/*
* checks if the audio codec index corresponds to Vorbis (webm) codec
* args:
* codec_ind - audio codec list index
*
* asserts:
* none
*
* returns: 1 true; 0 false
*/
int encoder_check_webm_audio_codec(int codec_ind);
/*
* get the audio codec index for Vorbis (webm) codec
* args:
* none
*
* asserts:
* none
*
* returns: index for Vorbis codec or -1 if error
*/
int encoder_get_webm_audio_codec_index();
/*
* get the mkv codec private data
* args:
* codec_ind - codec list index
*
* asserts:
* none
*
* returns: pointer to mkvCodecPriv data
*/
void *encoder_get_video_mkvCodecPriv(int codec_ind);
/*
* set the video codec mkv private data
* args:
* encoder_ctx - pointer to encoder context
*
* asserts:
* encoder_ctx is not null
*
* returns: mkvCodecPriv size
*/
int encoder_set_video_mkvCodecPriv(encoder_context_t *encoder_ctx);
/*
* get the mkv codec private data
* args:
* codec_ind - codec list index
*
* asserts:
* none
*
* returns: pointer to mkvCodecPriv data
*/
void *encoder_get_audio_mkvCodecPriv(int codec_ind);
/*
* set the audio codec mkv private data
* args:
* encoder_ctx - pointer to encoder context
*
* asserts:
* encoder_ctx is not null
*
* returns: mkvCodecPriv size
*/
int encoder_set_audio_mkvCodecPriv(encoder_context_t *encoder_ctx);
/*
* get an estimated write loop sleep time to avoid a ring buffer overrun
* args:
* mode: scheduler mode:
* 0 - linear funtion; 1 - exponencial funtion
* thresh: ring buffer threshold in wich scheduler becomes active:
* [0.2 (20%) - 0.9 (90%)]
* max_time - maximum scheduler time (in ms)
*
* asserts:
* none
*
* returns: estimate sleep time (milisec)
*/
double encoder_buff_scheduler(int mode, double thresh, double max_time);
/*
* store unprocessed input video frame in video ring buffer
* args:
* frame - pointer to unprocessed frame data
* size - frame size (in bytes)
* timestamp - frame timestamp (in nanosec)
* isKeyframe - flag if it's a key(IDR) frame
*
* asserts:
* none
*
* returns: error code
*/
int encoder_add_video_frame(uint8_t *frame, int size, int64_t timestamp, int isKeyframe);
/*
* process next video frame on the ring buffer (encode and mux to file)
* args:
* encoder_ctx - pointer to encoder context
*
* asserts:
* encoder_ctx is not null
*
* returns: error code
*/
int encoder_process_next_video_buffer(encoder_context_t *encoder_ctx);
/*
* process all used video frames from buffer
* args:
* encoder_ctx - pointer to encoder context
*
* asserts:
* encoder_ctx is not null
*
* returns: error code
*/
int encoder_flush_video_buffer(encoder_context_t *encoder_ctx);
/*
* process audio buffer (encode and mux to file)
* args:
* encoder_ctx - pointer to encoder context
* data - audio buffer
*
* asserts:
* encoder_ctx is not null
*
* returns: error code
*/
int encoder_process_audio_buffer(encoder_context_t *encoder_ctx, void *data);
/*
* process all delayed audio frames from libavcodec
* args:
* encoder_ctx - pointer to encoder context
*
* asserts:
* encoder_ctx is not null
*
* returns: error code
*/
int encoder_flush_audio_buffer(encoder_context_t *encoder_ctx);
/*
* encode video frame
* args:
* encoder_ctx - pointer to encoder context
* yuv_frame - yuyv input frame
*
* asserts:
* none
*
* returns: encoded buffer size
*/
int encoder_encode_video(encoder_context_t *encoder_ctx, void *yuv_frame);
/*
* encode audio
* args:
* encoder_ctx - pointer to encoder context
* audio_data - pointer to audio pcm data
*
* asserts:
* none
*
* returns: encoded buffer size
*/
int encoder_encode_audio(encoder_context_t *encoder_ctx, void *audio_data);
/*
* close and clean encoder context
* args:
* encoder_ctx - pointer to encoder context data
*
* asserts:
* none
*
* returns: none
*/
void encoder_close(encoder_context_t *encoder_ctx);
/*
* mux a video frame
* args:
* encoder_ctx - pointer to encoder context
*
* asserts:
* encoder_ctx is not null;
*
* returns: none
*/
int encoder_write_video_data(encoder_context_t *encoder_ctx);
/*
* mux a audio frame
* args:
* encoder_ctx - pointer to encoder context
*
* asserts:
* encoder_ctx is not null;
*
* returns: none
*/
int encoder_write_audio_data(encoder_context_t *encoder_ctx);
/*
* function to determine if enought free space is available
* args:
* treshold: limit treshold in Kbytes (min. free space)
*
* asserts:
* none
*
* returns: 1 if still enough free space left on disk
* 0 otherwise
*/
int encoder_disk_supervisor(int treshold, const char *path);
__END_DECLS
#endif
|