FFmpeg
Data Structures | Macros | Functions | Variables
flashsv2enc.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <zlib.h>
#include "libavutil/imgutils.h"
#include "libavutil/mem.h"
#include "avcodec.h"
#include "codec_internal.h"
#include "encode.h"
#include "put_bits.h"
#include "zlib_wrapper.h"

Go to the source code of this file.

Data Structures

struct  Block
 
struct  Palette
 
struct  FlashSV2Context
 

Macros

#define HAS_IFRAME_IMAGE   0x02
 
#define HAS_PALLET_INFO   0x01
 
#define COLORSPACE_BGR   0x00
 
#define COLORSPACE_15_7   0x10
 
#define HAS_DIFF_BLOCKS   0x04
 
#define ZLIB_PRIME_COMPRESS_CURRENT   0x02
 
#define ZLIB_PRIME_COMPRESS_PREVIOUS   0x01
 
#define FLASHSV2_DUMB
 
#define ABSDIFF(a, b)   (abs((int)(a)-(int)(b)))
 

Functions

static av_cold void cleanup (FlashSV2Context *s)
 
static void init_blocks (FlashSV2Context *s, Block *blocks, uint8_t *encbuf, uint8_t *databuf)
 
static void reset_stats (FlashSV2Context *s)
 
static int update_block_dimensions (FlashSV2Context *s, int block_width, int block_height)
 
static av_cold int flashsv2_encode_init (AVCodecContext *avctx)
 
static int new_key_frame (FlashSV2Context *s)
 
static int write_palette (FlashSV2Context *s, uint8_t *buf, int buf_size)
 
static int write_header (FlashSV2Context *s, uint8_t *buf, int buf_size)
 
static int write_block (Block *b, uint8_t *buf, int buf_size)
 
static int encode_zlib (Block *b, uint8_t *buf, unsigned long *buf_size, z_stream *zstream)
 
static int encode_zlibprime (Block *b, Block *prime, uint8_t *buf, int *buf_size, z_stream *zstream)
 
static int encode_bgr (Block *b, const uint8_t *src, int stride)
 
static unsigned pixel_color15 (const uint8_t *src)
 
static unsigned int chroma_diff (unsigned int c1, unsigned int c2)
 
static int pixel_color7_fast (Palette *palette, unsigned c15)
 
static int pixel_color7_slow (Palette *palette, unsigned color)
 
static unsigned pixel_bgr (const uint8_t *src)
 
static int write_pixel_15_7 (Palette *palette, uint8_t *dest, const uint8_t *src, int dist)
 
static int update_palette_index (Palette *palette)
 
static int generate_default_palette (Palette *palette)
 
static int generate_optimum_palette (Palette *palette, const uint8_t *image, int width, int height, int stride)
 
static int encode_15_7_sl (Palette *palette, uint8_t *dest, const uint8_t *src, int width, int dist)
 
static int encode_15_7 (Palette *palette, Block *b, const uint8_t *src, int stride, int dist)
 
static int encode_block (FlashSV2Context *s, Palette *palette, Block *b, Block *prev, const uint8_t *src, int stride, int dist, int keyframe)
 
static int compare_sl (FlashSV2Context *s, Block *b, const uint8_t *src, uint8_t *frame, uint8_t *key, int y, int keyframe)
 
static int mark_all_blocks (FlashSV2Context *s, const uint8_t *src, int stride, int keyframe)
 
static int encode_all_blocks (FlashSV2Context *s, int keyframe)
 
static int write_all_blocks (FlashSV2Context *s, uint8_t *buf, int buf_size)
 
static int write_bitstream (FlashSV2Context *s, const uint8_t *src, int stride, uint8_t *buf, int buf_size, int keyframe)
 
static void recommend_keyframe (FlashSV2Context *s, int *keyframe)
 
static int optimum_block_width (FlashSV2Context *s)
 
static int optimum_block_height (FlashSV2Context *s)
 
static int optimum_use15_7 (FlashSV2Context *s)
 
static int optimum_dist (FlashSV2Context *s)
 
static int reconfigure_at_keyframe (FlashSV2Context *s, const uint8_t *image, int stride)
 
static int flashsv2_encode_frame (AVCodecContext *avctx, AVPacket *pkt, const AVFrame *p, int *got_packet)
 
static av_cold int flashsv2_encode_end (AVCodecContext *avctx)
 

Variables

static const unsigned int default_screen_video_v2_palette [128]
 
const FFCodec ff_flashsv2_encoder
 

Detailed Description

Flash Screen Video Version 2 encoder

Author
Joshua Warner

Definition in file flashsv2enc.c.

Macro Definition Documentation

◆ HAS_IFRAME_IMAGE

#define HAS_IFRAME_IMAGE   0x02

Definition at line 57 of file flashsv2enc.c.

◆ HAS_PALLET_INFO

#define HAS_PALLET_INFO   0x01

Definition at line 58 of file flashsv2enc.c.

◆ COLORSPACE_BGR

#define COLORSPACE_BGR   0x00

Definition at line 60 of file flashsv2enc.c.

◆ COLORSPACE_15_7

#define COLORSPACE_15_7   0x10

Definition at line 61 of file flashsv2enc.c.

◆ HAS_DIFF_BLOCKS

#define HAS_DIFF_BLOCKS   0x04

Definition at line 62 of file flashsv2enc.c.

◆ ZLIB_PRIME_COMPRESS_CURRENT

#define ZLIB_PRIME_COMPRESS_CURRENT   0x02

Definition at line 63 of file flashsv2enc.c.

◆ ZLIB_PRIME_COMPRESS_PREVIOUS

#define ZLIB_PRIME_COMPRESS_PREVIOUS   0x01

Definition at line 64 of file flashsv2enc.c.

◆ FLASHSV2_DUMB

#define FLASHSV2_DUMB

Definition at line 68 of file flashsv2enc.c.

◆ ABSDIFF

#define ABSDIFF (   a,
  b 
)    (abs((int)(a)-(int)(b)))

Function Documentation

◆ cleanup()

static av_cold void cleanup ( FlashSV2Context s)
static

◆ init_blocks()

static void init_blocks ( FlashSV2Context s,
Block blocks,
uint8_t *  encbuf,
uint8_t *  databuf 
)
static

Definition at line 144 of file flashsv2enc.c.

Referenced by update_block_dimensions().

◆ reset_stats()

static void reset_stats ( FlashSV2Context s)
static

Definition at line 171 of file flashsv2enc.c.

Referenced by flashsv2_encode_init(), and reconfigure_at_keyframe().

◆ update_block_dimensions()

static int update_block_dimensions ( FlashSV2Context s,
int  block_width,
int  block_height 
)
static

Definition at line 182 of file flashsv2enc.c.

Referenced by flashsv2_encode_init(), and reconfigure_at_keyframe().

◆ flashsv2_encode_init()

static av_cold int flashsv2_encode_init ( AVCodecContext avctx)
static

Definition at line 209 of file flashsv2enc.c.

◆ new_key_frame()

static int new_key_frame ( FlashSV2Context s)
static

Definition at line 272 of file flashsv2enc.c.

Referenced by flashsv2_encode_frame().

◆ write_palette()

static int write_palette ( FlashSV2Context s,
uint8_t *  buf,
int  buf_size 
)
static

Definition at line 289 of file flashsv2enc.c.

Referenced by write_header().

◆ write_header()

static int write_header ( FlashSV2Context s,
uint8_t *  buf,
int  buf_size 
)
static

Definition at line 295 of file flashsv2enc.c.

Referenced by write_bitstream().

◆ write_block()

static int write_block ( Block b,
uint8_t *  buf,
int  buf_size 
)
static

Definition at line 325 of file flashsv2enc.c.

Referenced by write_all_blocks().

◆ encode_zlib()

static int encode_zlib ( Block b,
uint8_t *  buf,
unsigned long *  buf_size,
z_stream *  zstream 
)
static

Definition at line 365 of file flashsv2enc.c.

Referenced by encode_block().

◆ encode_zlibprime()

static int encode_zlibprime ( Block b,
Block prime,
uint8_t *  buf,
int *  buf_size,
z_stream *  zstream 
)
static

Definition at line 383 of file flashsv2enc.c.

Referenced by encode_block().

◆ encode_bgr()

static int encode_bgr ( Block b,
const uint8_t *  src,
int  stride 
)
static

Definition at line 411 of file flashsv2enc.c.

Referenced by encode_block().

◆ pixel_color15()

static unsigned pixel_color15 ( const uint8_t *  src)
inlinestatic

Definition at line 427 of file flashsv2enc.c.

Referenced by write_pixel_15_7().

◆ chroma_diff()

static unsigned int chroma_diff ( unsigned int  c1,
unsigned int  c2 
)
inlinestatic

Definition at line 432 of file flashsv2enc.c.

Referenced by pixel_color7_slow(), and write_pixel_15_7().

◆ pixel_color7_fast()

static int pixel_color7_fast ( Palette palette,
unsigned  c15 
)
inlinestatic

Definition at line 444 of file flashsv2enc.c.

Referenced by write_pixel_15_7().

◆ pixel_color7_slow()

static int pixel_color7_slow ( Palette palette,
unsigned  color 
)
static

Definition at line 449 of file flashsv2enc.c.

Referenced by update_palette_index().

◆ pixel_bgr()

static unsigned pixel_bgr ( const uint8_t *  src)
inlinestatic

Definition at line 464 of file flashsv2enc.c.

Referenced by write_pixel_15_7().

◆ write_pixel_15_7()

static int write_pixel_15_7 ( Palette palette,
uint8_t *  dest,
const uint8_t *  src,
int  dist 
)
static

Definition at line 469 of file flashsv2enc.c.

Referenced by encode_15_7_sl().

◆ update_palette_index()

static int update_palette_index ( Palette palette)
static

Definition at line 487 of file flashsv2enc.c.

Referenced by generate_default_palette().

◆ generate_default_palette()

static int generate_default_palette ( Palette palette)
static

Definition at line 530 of file flashsv2enc.c.

Referenced by reconfigure_at_keyframe().

◆ generate_optimum_palette()

static int generate_optimum_palette ( Palette palette,
const uint8_t *  image,
int  width,
int  height,
int  stride 
)
static

Definition at line 538 of file flashsv2enc.c.

Referenced by reconfigure_at_keyframe().

◆ encode_15_7_sl()

static int encode_15_7_sl ( Palette palette,
uint8_t *  dest,
const uint8_t *  src,
int  width,
int  dist 
)
inlinestatic

Definition at line 545 of file flashsv2enc.c.

Referenced by encode_15_7().

◆ encode_15_7()

static int encode_15_7 ( Palette palette,
Block b,
const uint8_t *  src,
int  stride,
int  dist 
)
static

Definition at line 555 of file flashsv2enc.c.

Referenced by encode_block().

◆ encode_block()

static int encode_block ( FlashSV2Context s,
Palette palette,
Block b,
Block prev,
const uint8_t *  src,
int  stride,
int  dist,
int  keyframe 
)
static

Definition at line 572 of file flashsv2enc.c.

Referenced by encode_all_blocks().

◆ compare_sl()

static int compare_sl ( FlashSV2Context s,
Block b,
const uint8_t *  src,
uint8_t *  frame,
uint8_t *  key,
int  y,
int  keyframe 
)
static

Definition at line 609 of file flashsv2enc.c.

Referenced by mark_all_blocks().

◆ mark_all_blocks()

static int mark_all_blocks ( FlashSV2Context s,
const uint8_t *  src,
int  stride,
int  keyframe 
)
static

Definition at line 627 of file flashsv2enc.c.

Referenced by write_bitstream().

◆ encode_all_blocks()

static int encode_all_blocks ( FlashSV2Context s,
int  keyframe 
)
static

Definition at line 648 of file flashsv2enc.c.

Referenced by write_bitstream().

◆ write_all_blocks()

static int write_all_blocks ( FlashSV2Context s,
uint8_t *  buf,
int  buf_size 
)
static

Definition at line 689 of file flashsv2enc.c.

Referenced by write_bitstream().

◆ write_bitstream()

static int write_bitstream ( FlashSV2Context s,
const uint8_t *  src,
int  stride,
uint8_t *  buf,
int  buf_size,
int  keyframe 
)
static

Definition at line 707 of file flashsv2enc.c.

Referenced by flashsv2_encode_frame().

◆ recommend_keyframe()

static void recommend_keyframe ( FlashSV2Context s,
int *  keyframe 
)
static

Definition at line 736 of file flashsv2enc.c.

Referenced by flashsv2_encode_frame().

◆ optimum_block_width()

static int optimum_block_width ( FlashSV2Context s)
static

Definition at line 762 of file flashsv2enc.c.

Referenced by reconfigure_at_keyframe().

◆ optimum_block_height()

static int optimum_block_height ( FlashSV2Context s)
static

Definition at line 774 of file flashsv2enc.c.

Referenced by reconfigure_at_keyframe().

◆ optimum_use15_7()

static int optimum_use15_7 ( FlashSV2Context s)
static

Definition at line 786 of file flashsv2enc.c.

Referenced by reconfigure_at_keyframe().

◆ optimum_dist()

static int optimum_dist ( FlashSV2Context s)
static

Definition at line 801 of file flashsv2enc.c.

Referenced by flashsv2_encode_frame().

◆ reconfigure_at_keyframe()

static int reconfigure_at_keyframe ( FlashSV2Context s,
const uint8_t *  image,
int  stride 
)
static

Definition at line 816 of file flashsv2enc.c.

Referenced by flashsv2_encode_frame().

◆ flashsv2_encode_frame()

static int flashsv2_encode_frame ( AVCodecContext avctx,
AVPacket pkt,
const AVFrame p,
int *  got_packet 
)
static

Definition at line 853 of file flashsv2enc.c.

◆ flashsv2_encode_end()

static av_cold int flashsv2_encode_end ( AVCodecContext avctx)
static

Definition at line 904 of file flashsv2enc.c.

Variable Documentation

◆ default_screen_video_v2_palette

const unsigned int default_screen_video_v2_palette[128]
static
Initial value:
= {
0x00000000, 0x00333333, 0x00666666, 0x00999999, 0x00CCCCCC, 0x00FFFFFF,
0x00330000, 0x00660000, 0x00990000, 0x00CC0000, 0x00FF0000, 0x00003300,
0x00006600, 0x00009900, 0x0000CC00, 0x0000FF00, 0x00000033, 0x00000066,
0x00000099, 0x000000CC, 0x000000FF, 0x00333300, 0x00666600, 0x00999900,
0x00CCCC00, 0x00FFFF00, 0x00003333, 0x00006666, 0x00009999, 0x0000CCCC,
0x0000FFFF, 0x00330033, 0x00660066, 0x00990099, 0x00CC00CC, 0x00FF00FF,
0x00FFFF33, 0x00FFFF66, 0x00FFFF99, 0x00FFFFCC, 0x00FF33FF, 0x00FF66FF,
0x00FF99FF, 0x00FFCCFF, 0x0033FFFF, 0x0066FFFF, 0x0099FFFF, 0x00CCFFFF,
0x00CCCC33, 0x00CCCC66, 0x00CCCC99, 0x00CCCCFF, 0x00CC33CC, 0x00CC66CC,
0x00CC99CC, 0x00CCFFCC, 0x0033CCCC, 0x0066CCCC, 0x0099CCCC, 0x00FFCCCC,
0x00999933, 0x00999966, 0x009999CC, 0x009999FF, 0x00993399, 0x00996699,
0x0099CC99, 0x0099FF99, 0x00339999, 0x00669999, 0x00CC9999, 0x00FF9999,
0x00666633, 0x00666699, 0x006666CC, 0x006666FF, 0x00663366, 0x00669966,
0x0066CC66, 0x0066FF66, 0x00336666, 0x00996666, 0x00CC6666, 0x00FF6666,
0x00333366, 0x00333399, 0x003333CC, 0x003333FF, 0x00336633, 0x00339933,
0x0033CC33, 0x0033FF33, 0x00663333, 0x00993333, 0x00CC3333, 0x00FF3333,
0x00003366, 0x00336600, 0x00660033, 0x00006633, 0x00330066, 0x00663300,
0x00336699, 0x00669933, 0x00993366, 0x00339966, 0x00663399, 0x00996633,
0x006699CC, 0x0099CC66, 0x00CC6699, 0x0066CC99, 0x009966CC, 0x00CC9966,
0x0099CCFF, 0x00CCFF99, 0x00FF99CC, 0x0099FFCC, 0x00CC99FF, 0x00FFCC99,
0x00111111, 0x00222222, 0x00444444, 0x00555555, 0x00AAAAAA, 0x00BBBBBB,
0x00DDDDDD, 0x00EEEEEE
}

Definition at line 505 of file flashsv2enc.c.

Referenced by generate_default_palette().

◆ ff_flashsv2_encoder

const FFCodec ff_flashsv2_encoder
Initial value:
= {
.p.name = "flashsv2",
CODEC_LONG_NAME("Flash Screen Video Version 2"),
.p.type = AVMEDIA_TYPE_VIDEO,
.priv_data_size = sizeof(FlashSV2Context),
.p.pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_BGR24, AV_PIX_FMT_NONE },
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
}

Definition at line 913 of file flashsv2enc.c.

AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: codec_internal.h:43
AV_PIX_FMT_BGR24
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:76
flashsv2_encode_frame
static int flashsv2_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *p, int *got_packet)
Definition: flashsv2enc.c:853
FF_CODEC_ENCODE_CB
#define FF_CODEC_ENCODE_CB(func)
Definition: codec_internal.h:320
AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
Definition: codec.h:159
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:296
AV_CODEC_ID_FLASHSV2
@ AV_CODEC_ID_FLASHSV2
Definition: codec_id.h:183
flashsv2_encode_end
static av_cold int flashsv2_encode_end(AVCodecContext *avctx)
Definition: flashsv2enc.c:904
flashsv2_encode_init
static av_cold int flashsv2_encode_init(AVCodecContext *avctx)
Definition: flashsv2enc.c:209
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:368
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
FlashSV2Context
Definition: flashsv2enc.c:88
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201