• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2013 Ilia Mirkin
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20  * OTHER DEALINGS IN THE SOFTWARE.
21  */
22 
23 #ifndef NV84_VIDEO_H_
24 #define NV84_VIDEO_H_
25 
26 #include "vl/vl_decoder.h"
27 #include "vl/vl_video_buffer.h"
28 #include "vl/vl_types.h"
29 
30 #include "vl/vl_mpeg12_bitstream.h"
31 
32 #include "util/u_video.h"
33 
34 #include "nv50/nv50_context.h"
35 
36 /* These are expected to be on their own pushbufs */
37 #define SUBC_BSP(m) 2, (m)
38 #define SUBC_VP(m) 2, (m)
39 
40 union pipe_desc {
41    struct pipe_picture_desc *base;
42    struct pipe_mpeg12_picture_desc *mpeg12;
43    struct pipe_mpeg4_picture_desc *mpeg4;
44    struct pipe_vc1_picture_desc *vc1;
45    struct pipe_h264_picture_desc *h264;
46 };
47 
48 struct nv84_video_buffer {
49    struct pipe_video_buffer base;
50    struct pipe_resource *resources[VL_NUM_COMPONENTS];
51    struct pipe_sampler_view *sampler_view_planes[VL_NUM_COMPONENTS];
52    struct pipe_sampler_view *sampler_view_components[VL_NUM_COMPONENTS];
53    struct pipe_surface *surfaces[VL_NUM_COMPONENTS * 2];
54 
55    struct nouveau_bo *interlaced, *full;
56    int mvidx;
57    unsigned frame_num, frame_num_max;
58 };
59 
60 struct nv84_decoder {
61    struct pipe_video_codec base;
62    struct nouveau_client *client;
63    struct nouveau_object *bsp_channel, *vp_channel, *bsp, *vp;
64    struct nouveau_pushbuf *bsp_pushbuf, *vp_pushbuf;
65    struct nouveau_bufctx *bsp_bufctx, *vp_bufctx;
66 
67    struct nouveau_bo *bsp_fw, *bsp_data;
68    struct nouveau_bo *vp_fw, *vp_data;
69    struct nouveau_bo *mbring, *vpring;
70 
71    /*
72     * states:
73     *  0: init
74     *  1: vpring/mbring cleared, bsp is ready
75     *  2: bsp is done, vp is ready
76     * and then vp it back to 1
77     */
78    struct nouveau_bo *fence;
79 
80    struct nouveau_bo *bitstream;
81    struct nouveau_bo *vp_params;
82 
83    size_t vp_fw2_offset;
84 
85    unsigned frame_mbs, frame_size;
86    /* VPRING layout:
87         RESIDUAL
88         CTRL
89         DEBLOCK
90         0x1000
91    */
92    unsigned vpring_deblock, vpring_residual, vpring_ctrl;
93 
94 
95    struct vl_mpg12_bs *mpeg12_bs;
96 
97    struct nouveau_bo *mpeg12_bo;
98    void *mpeg12_mb_info;
99    uint16_t *mpeg12_data;
100    const int *zscan;
101    uint8_t mpeg12_intra_matrix[64];
102    uint8_t mpeg12_non_intra_matrix[64];
103 };
104 
mb(uint32_t coord)105 static inline uint32_t mb(uint32_t coord)
106 {
107    return (coord + 0xf)>>4;
108 }
109 
mb_half(uint32_t coord)110 static inline uint32_t mb_half(uint32_t coord)
111 {
112    return (coord + 0x1f)>>5;
113 }
114 
115 int
116 nv84_decoder_bsp(struct nv84_decoder *dec,
117                  struct pipe_h264_picture_desc *desc,
118                  unsigned num_buffers,
119                  const void *const *data,
120                  const unsigned *num_bytes,
121                  struct nv84_video_buffer *dest);
122 
123 void
124 nv84_decoder_vp_h264(struct nv84_decoder *dec,
125                      struct pipe_h264_picture_desc *desc,
126                      struct nv84_video_buffer *dest);
127 
128 void
129 nv84_decoder_vp_mpeg12_mb(struct nv84_decoder *dec,
130                           struct pipe_mpeg12_picture_desc *desc,
131                           const struct pipe_mpeg12_macroblock *mb);
132 
133 void
134 nv84_decoder_vp_mpeg12(struct nv84_decoder *dec,
135                        struct pipe_mpeg12_picture_desc *desc,
136                        struct nv84_video_buffer *dest);
137 
138 #endif
139