• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * viddec_mpeg2_frame_attr.c
3  * -------------------------
4  * This is a helper file for viddec_mpeg2_workload.c to translate the data
5  * stored in the parser context into frame attributes in the workload.
6  */
7 
8 #include "viddec_mpeg2.h"
9 
10 /* viddec_mpeg2_print_attr() - Prints collected frame attributes             */
viddec_mpeg2_print_attr(viddec_frame_attributes_t * attr)11 static inline void viddec_mpeg2_print_attr(viddec_frame_attributes_t *attr)
12 {
13     unsigned int index = 0;
14 
15     MPEG2_FA_DEB("Content_Size=%dx%d\n",        attr->cont_size.width,
16                                                 attr->cont_size.height);
17     MPEG2_FA_DEB("Repeat=%d\n",                 attr->mpeg2.repeat_first_field);
18     MPEG2_FA_DEB("Frame_Type=%d\n",             attr->frame_type);
19     MPEG2_FA_DEB("Temporal_Reference=%d\n",     attr->mpeg2.temporal_ref);
20     MPEG2_FA_DEB("Top_Field_First=%d\n",        attr->mpeg2.top_field_first);
21     MPEG2_FA_DEB("Progressive_Frame=%d\n",      attr->mpeg2.progressive_frame);
22     MPEG2_FA_DEB("Picture_Struct=%d\n",         attr->mpeg2.picture_struct);
23     MPEG2_FA_DEB("Pan_Scan_Offsets=%d\n",       attr->mpeg2.number_of_frame_center_offsets);
24 
25     for (index = 0; index < attr->mpeg2.number_of_frame_center_offsets; index++)
26     {
27         MPEG2_FA_DEB("\tPan_Scan_Offset_%d= %dx%d\n", index,
28         attr->mpeg2.frame_center_offset[index].horz,
29         attr->mpeg2.frame_center_offset[index].vert);
30     }
31 
32     return;
33 }
34 
35 /* viddec_mpeg2_set_default_values() - Resets attributes that are optional   */
36 /* in the bitstream to their default values.                                 */
viddec_mpeg2_set_default_values(viddec_frame_attributes_t * attrs)37 static inline void viddec_mpeg2_set_default_values(viddec_frame_attributes_t *attrs)
38 {
39     unsigned int index = 0;
40 
41     attrs->mpeg2.number_of_frame_center_offsets = 0;
42     for (index = 0; index < MPEG2_MAX_VID_OFFSETS ; index++)
43     {
44         attrs->mpeg2.frame_center_offset[index].horz = 0;
45         attrs->mpeg2.frame_center_offset[index].vert = 0;
46     }
47 
48     return;
49 }
50 
51 /* viddec_mpeg2_translate_attr() - Translates metadata parsed into frame     */
52 /* attributes in the workload                                                */
viddec_mpeg2_translate_attr(void * parent,void * ctxt)53 void viddec_mpeg2_translate_attr(void *parent, void *ctxt)
54 {
55     /* Get MPEG2 Parser context */
56     struct viddec_mpeg2_parser *parser = (struct viddec_mpeg2_parser *) ctxt;
57 
58     /* Get workload */
59     viddec_workload_t *wl = viddec_pm_get_header( parent );
60 
61     /* Get attributes in workload */
62     viddec_frame_attributes_t *attrs = &wl->attrs;
63 
64     /* Get the default values for optional attributes */
65     viddec_mpeg2_set_default_values(attrs);
66 
67     /* Populate attributes from parser context */
68     /* Content Size */
69     attrs->cont_size.height         = ((parser->info.seq_ext.vertical_size_extension << 12)
70                                         | parser->info.seq_hdr.vertical_size_value);
71     attrs->cont_size.width          = ((parser->info.seq_ext.horizontal_size_extension << 12)
72                                         | parser->info.seq_hdr.horizontal_size_value);
73 
74     /* Repeat field */
75     attrs->mpeg2.repeat_first_field = parser->info.pic_cod_ext.repeat_first_field;
76 
77     /* Temporal Reference */
78     attrs->mpeg2.temporal_ref       = parser->info.pic_hdr.temporal_reference;
79 
80     /* Top field first */
81     attrs->mpeg2.top_field_first    = parser->info.pic_cod_ext.top_field_first;
82 
83     /* Progressive frame */
84     attrs->mpeg2.progressive_frame  = parser->info.pic_cod_ext.progressive_frame;
85 
86     /* Picture Structure */
87     attrs->mpeg2.picture_struct     = parser->info.pic_cod_ext.picture_structure;
88 
89     /* Populate the frame type */
90     switch (parser->info.pic_hdr.picture_coding_type)
91     {
92         case MPEG2_PC_TYPE_I: attrs->frame_type = VIDDEC_FRAME_TYPE_I; break;
93         case MPEG2_PC_TYPE_P: attrs->frame_type = VIDDEC_FRAME_TYPE_P; break;
94         case MPEG2_PC_TYPE_B: attrs->frame_type = VIDDEC_FRAME_TYPE_B; break;
95         default:              attrs->frame_type = VIDDEC_FRAME_TYPE_INVALID;
96     }
97 
98     /* Update PanScan data */
99     if (parser->mpeg2_curr_frame_headers & MPEG2_HEADER_PIC_DISP_EXT)
100     {
101         unsigned int index = 0;
102         attrs->mpeg2.number_of_frame_center_offsets = parser->mpeg2_num_pan_scan_offsets;
103         for (index = 0; index < parser->mpeg2_num_pan_scan_offsets; index++)
104         {
105             attrs->mpeg2.frame_center_offset[index].horz = parser->info.pic_disp_ext.frame_center_horizontal_offset[index];
106             attrs->mpeg2.frame_center_offset[index].vert = parser->info.pic_disp_ext.frame_center_vertical_offset[index];
107         }
108     }
109 
110     /* Print frame attributes */
111     viddec_mpeg2_print_attr(attrs);
112 
113     return;
114 }
115