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