annotate DOCS/tech/libmpcodecs.txt @ 7397:379e379bd4f4

some words and drawing about video path
author arpi
date Sun, 15 Sep 2002 01:18:39 +0000
parents
children 56bb20a00bc9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7397
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
1 The libMPcodecs API details, hints - by A'rpi
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
2 ==================================
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
3
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
4 See also: colorspaces.txt, codec-devel.txt, dr-methods.txt
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
5
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
6 The VIDEO path:
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
7 ===============
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
8
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
9 [MPlayer core]
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
10 | (1)
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
11 _____V______ (2) /~~~~~~~~~~\ (3,4) |~~~~~~|
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
12 | | -----> | vd_XXX.c | -------> | vd.c |
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
13 | decvideo | \__________/ <-(3a)-- |______|
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
14 | | -----, ,.............(3a,4a).....:
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
15 ~~~~~~~~~~~~ (6) V V
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
16 /~~~~~~~~\ /~~~~~~~~\ (8)
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
17 | vf_X.c | --> | vf_Y.c | ----> vf_vo.c / ve_XXX.c
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
18 \________/ \________/
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
19 | ^
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
20 (7) | |~~~~~~| : (7a)
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
21 `-> | vf.c |...:
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
22 |______|
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
23
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
24 Short description of video path:
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
25 1. mplayer/mencoder core requests the decoding of a compressed video frame:
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
26 calls decvideo.c::decode_video()
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
27
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
28 2. decode_video() calls the previously ( init_video() ) selected video codec
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
29 (vd_XXXX.c file, where XXXX == vfm name, see the 'driver' line of codecs.conf)
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
30
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
31 3. the codec should initialize output device before decoding the first frame,
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
32 it may happen in init() or at the middle of the first decode(). see 3.a.
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
33 it means calling vd.c::mpcodecs_config_vo() with the image dimensions,
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
34 and the _preferred_ (mean: internal, native, best) colorspace.
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
35 NOTE: this colorspace may not be equal to the actually used colorspace, it's
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
36 just a _hint_ for the csp matching algorithm, and mainly used _only_ when
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
37 csp conversion is required, as input format of the converter.
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
38
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
39 3.a. selecting the best output colorspace:
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
40 the vd.c::mpcodecs_config_vo() function will go through the outfmt list
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
41 defined by codecs.conf's 'out' lines, and query both vd (codec) and vo
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
42 (output device/filter/encoder) if it's supported or not.
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
43
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
44 For the vo, it calls the query_format() func of vf_XXX.c or ve_XXX.c.
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
45 It should return a set of feature flags, the most important ons for this
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
46 stage are: VFCAP_CSP_SUPPORTED (csp supported directly or by conversion)
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
47 and VFCAP_CSP_SUPPORTED_BY_HW (csp supported WITHOUT any conversion).
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
48
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
49 For the vd (codec), control() with VDCTRL_QUERY_FORMAT will be called.
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
50 If it doesn't implement VDCTRL_QUERY_FORMAT, (ie answers CONTROL_UNKNOWN
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
51 or CONTROL_NA) it will be assumed to be CONTROL_TRUE (csp supported)!
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
52
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
53 So, by default, if the list of supported colorspaces is constant, doesn't
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
54 depend on the actual file's/stream's header, it's enough to list them
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
55 in codecs.conf ('out' field), and don't implement VDCTRL_QUERY_FORMAT.
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
56 It's the case for the most codecs.
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
57
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
58 If the supported csp list depends on the file being decoded, list the
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
59 possible out formats (colorspaces) in codecs.conf, and implement the
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
60 VDCTRL_QUERY_FORMAT to test the availability of the given csp for the
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
61 given video file/stream.
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
62
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
63 The vd.c core will find the best matching colorspace, depending on the
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
64 VFCAP_CSP_SUPPORTED_BY_HW flag (see vfcap.h). If no match at all, it
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
65 will try again with the 'scale' filter inserted between vd and vo.
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
66 If still no match, it will fail :(
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
67
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
68 4. requesting buffer for the decoded frame:
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
69 The codec have to call mpcodecs_get_image() with proper imgtype & imgflag.
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
70 It will find the optimal buffering setup (preferred stride, alignment etc)
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
71 and return a pointer to the allocated and filled up mpi (mp_image_t*) struct.
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
72 The 'imgtype' controls the buffering setup, ie STATIC (just one buffer,
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
73 it 'remembers' its contents between frames), TEMP (write-only, full update),
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
74 EXPORT (memory allocation is done by the codec, not recommended) and so on.
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
75 The 'imgflags' set up the limits for the buffer, ie stride limitations,
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
76 readability, remembering content etc. See mp_image.h for the short descr.
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
77 See dr-methods.txt for the explanation of buffer importing and mpi imgtypes.
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
78
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
79 Always try to implement stride support! (stride == bytes per line)
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
80 If no stride support, then stride==bytes_per_pixel*image_width.
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
81 If you have stride supoprt in your decoder, use the mpi->stride[] value
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
82 for the byte_per_line for each plane.
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
83 Also take care of other imgflags, like MP_IMGFLAG_PRESERVE and
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
84 MP_IMGFLAG_READABLE, MP_IMGFLAG_COMMON_STRIDE and MP_IMGFLAG_COMMON_PLANE!
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
85 The file mp_image.h contains description of flags in comments, read it!
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
86 Ask for help on -dev-eng, describing the behaviour your codec, if unsure.
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
87
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
88 4.a. buffer allocation, vd.c::mpcodecs_get_image():
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
89 If the requested buffer imgtype!=EXPORT, then vd.c will try to do
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
90 direct rendering, ie. asks the next filter/vo for the buffer allocation.
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
91 It's done by calling get_image() of the vf_XXX.c file.
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
92 If it was successful, the imgflag MP_IMGFLAG_DIRECT will be set, and one
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
93 memcpy() will be saved when passing the data from vd to the next filter/vo.
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
94 See dr-methods.txt for details and examples.
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
95
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
96 5. decode the frame, to the mpi structure requested at 4, then return the mpi
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
97 to decvideo.c. Return NULL if the decoding failed or skipped frame.
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
98
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
99 6. decvideo.c::decode_video() will now pass the 'mpi' to the next filter (vf_X).
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
100
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
101 7. the filter's (vf_X) put_image() then requests a new mpi buffer by calling
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
102 vf.c::vf_get_image().
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
103
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
104 7.a. vf.c::vf_get_image() will try to get direct rendering, by asking the
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
105 next fliter to do the buffer allocation (calls vf_Y's get_image()).
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
106 if it fails, it will fallback to normal system memory allocation.
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
107
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
108 8. when we're over the whole filter chain (multiple filters can be connected,
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
109 even the same filter multiple times) then the last, 'leaf' filter will be
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
110 called. The only difference between leaf and non-leaf filter is that leaf
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
111 filter have to implement the whole filter api.
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
112 Leaf filters are now: vf_vo.c (wrapper over libvo) and ve_XXX.c (video
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
113 encoders used by mencoder).
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
114
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
115
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
116 The AUDIO path:
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
117 ===============
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
118 TODO!!!