| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. Use of this | |
| 2 // source code is governed by a BSD-style license that can be found in the | |
| 3 // LICENSE file. | |
| 4 | |
| 5 #include "media/omx/omx_configurator.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 | |
| 9 namespace media { | |
| 10 | |
| 11 static std::string GetCodecName(OmxConfigurator::Codec codec) { | |
| 12 switch (codec) { | |
| 13 case OmxConfigurator::kCodecH264: | |
| 14 return "avc"; | |
| 15 case OmxConfigurator::kCodecH263: | |
| 16 return "h263"; | |
| 17 case OmxConfigurator::kCodecMpeg4: | |
| 18 return "mpeg4"; | |
| 19 case OmxConfigurator::kCodecVc1: | |
| 20 return "vc1"; | |
| 21 default: | |
| 22 break; | |
| 23 } | |
| 24 NOTREACHED(); | |
| 25 return ""; | |
| 26 } | |
| 27 | |
| 28 std::string OmxDecoderConfigurator::GetRoleName() const { | |
| 29 return "video_decoder." + GetCodecName(input_format().codec); | |
| 30 } | |
| 31 | |
| 32 bool OmxDecoderConfigurator::ConfigureIOPorts( | |
| 33 OMX_COMPONENTTYPE* component, | |
| 34 OMX_PARAM_PORTDEFINITIONTYPE* input_port_def, | |
| 35 OMX_PARAM_PORTDEFINITIONTYPE* output_port_def) const { | |
| 36 // Configure the input port. | |
| 37 if (input_format().codec == kCodecNone) { | |
| 38 LOG(ERROR) << "Unsupported codec " << input_format().codec; | |
| 39 return false; | |
| 40 } | |
| 41 if (input_format().codec == kCodecH264) | |
| 42 input_port_def->format.video.eCompressionFormat = OMX_VIDEO_CodingAVC; | |
| 43 else if (input_format().codec == kCodecMpeg4) | |
| 44 input_port_def->format.video.eCompressionFormat = OMX_VIDEO_CodingMPEG4; | |
| 45 else if (input_format().codec == kCodecH263) | |
| 46 input_port_def->format.video.eCompressionFormat = OMX_VIDEO_CodingH263; | |
| 47 else if (input_format().codec == kCodecVc1) | |
| 48 input_port_def->format.video.eCompressionFormat = OMX_VIDEO_CodingWMV; | |
| 49 | |
| 50 // Assumes 480P. | |
| 51 input_port_def->format.video.nFrameWidth = 720; | |
| 52 input_port_def->format.video.nFrameHeight = 480; | |
| 53 OMX_ERRORTYPE omxresult = OMX_ErrorNone; | |
| 54 omxresult = OMX_SetParameter(component, | |
| 55 OMX_IndexParamPortDefinition, | |
| 56 input_port_def); | |
| 57 if (omxresult != OMX_ErrorNone) { | |
| 58 LOG(ERROR) << "SetParameter(OMX_IndexParamPortDefinition) " | |
| 59 "for input port failed"; | |
| 60 return false; | |
| 61 } | |
| 62 return true; | |
| 63 } | |
| 64 | |
| 65 std::string OmxEncoderConfigurator::GetRoleName() const { | |
| 66 return "video_encoder." + GetCodecName(output_format().codec); | |
| 67 } | |
| 68 | |
| 69 bool OmxEncoderConfigurator::ConfigureIOPorts( | |
| 70 OMX_COMPONENTTYPE* component, | |
| 71 OMX_PARAM_PORTDEFINITIONTYPE* input_port_def, | |
| 72 OMX_PARAM_PORTDEFINITIONTYPE* output_port_def) const { | |
| 73 // TODO(jiesun): Add support for other format than MPEG4. | |
| 74 DCHECK_EQ(kCodecMpeg4, output_format().codec); | |
| 75 // Configure the input port. | |
| 76 input_port_def->format.video.nFrameWidth = | |
| 77 input_format().video_header.width; | |
| 78 input_port_def->format.video.nFrameHeight = | |
| 79 input_format().video_header.height; | |
| 80 OMX_ERRORTYPE omxresult = OMX_ErrorNone; | |
| 81 omxresult = OMX_SetParameter(component, | |
| 82 OMX_IndexParamPortDefinition, | |
| 83 input_port_def); | |
| 84 if (omxresult != OMX_ErrorNone) { | |
| 85 LOG(ERROR) << "SetParameter(OMX_IndexParamPortDefinition) " | |
| 86 "for input port failed"; | |
| 87 return false; | |
| 88 } | |
| 89 | |
| 90 // Configure the output port. | |
| 91 output_port_def->format.video.nFrameWidth = | |
| 92 input_format().video_header.width; | |
| 93 output_port_def->format.video.nFrameHeight = | |
| 94 input_format().video_header.height; | |
| 95 omxresult = OMX_SetParameter(component, | |
| 96 OMX_IndexParamPortDefinition, | |
| 97 output_port_def); | |
| 98 if (omxresult != OMX_ErrorNone) { | |
| 99 LOG(ERROR) << "SetParameter(OMX_IndexParamPortDefinition) " | |
| 100 "for output port failed"; | |
| 101 return false; | |
| 102 } | |
| 103 | |
| 104 if (output_format().codec == kCodecMpeg4) { | |
| 105 OMX_VIDEO_PARAM_MPEG4TYPE mp4_type; | |
| 106 omxresult = OMX_GetParameter(component, | |
| 107 OMX_IndexParamVideoMpeg4, | |
| 108 &mp4_type); | |
| 109 if (omxresult != OMX_ErrorNone) { | |
| 110 LOG(ERROR) << "GetParameter(OMX_IndexParamVideoMpeg4) failed"; | |
| 111 return false; | |
| 112 } | |
| 113 // TODO(jiesun): verify if other vendors had the same definition. | |
| 114 // Specify the frame rate. | |
| 115 mp4_type.nTimeIncRes = output_format().video_header.frame_rate * 2; | |
| 116 // Specify how many P frames between adjacent intra frames. | |
| 117 mp4_type.nPFrames = output_format().video_header.i_dist - 1; | |
| 118 omxresult = OMX_SetParameter(component, | |
| 119 OMX_IndexParamVideoMpeg4, | |
| 120 &mp4_type); | |
| 121 if (omxresult != OMX_ErrorNone) { | |
| 122 LOG(ERROR) << "SetParameter(OMX_IndexParamVideoMpeg4) failed"; | |
| 123 return false; | |
| 124 } | |
| 125 } | |
| 126 | |
| 127 OMX_VIDEO_PARAM_BITRATETYPE bitrate; | |
| 128 omxresult = OMX_GetParameter(component, | |
| 129 OMX_IndexParamVideoBitrate, | |
| 130 &bitrate); | |
| 131 if (omxresult != OMX_ErrorNone) { | |
| 132 LOG(ERROR) << "GetParameter(OMX_IndexParamVideoBitrate) failed"; | |
| 133 return false; | |
| 134 } | |
| 135 | |
| 136 // TODO(jiesun): expose other rate control method that matters. | |
| 137 bitrate.eControlRate = OMX_Video_ControlRateConstant; | |
| 138 bitrate.nTargetBitrate = output_format().video_header.bit_rate; | |
| 139 omxresult = OMX_SetParameter(component, | |
| 140 OMX_IndexParamVideoBitrate, | |
| 141 &bitrate); | |
| 142 if (omxresult != OMX_ErrorNone) { | |
| 143 LOG(ERROR) << "SetParameter(OMX_IndexParamVideoBitrate) failed"; | |
| 144 return false; | |
| 145 } | |
| 146 | |
| 147 OMX_CONFIG_FRAMERATETYPE framerate; | |
| 148 omxresult = OMX_GetConfig(component, | |
| 149 OMX_IndexConfigVideoFramerate, | |
| 150 &framerate); | |
| 151 if (omxresult != OMX_ErrorNone) { | |
| 152 LOG(ERROR) << "GetParameter(OMX_IndexConfigVideoFramerate) failed"; | |
| 153 return false; | |
| 154 } | |
| 155 | |
| 156 framerate.xEncodeFramerate = | |
| 157 output_format().video_header.frame_rate << 16; // Q16 format. | |
| 158 omxresult = OMX_SetConfig(component, | |
| 159 OMX_IndexConfigVideoFramerate, | |
| 160 &framerate); | |
| 161 if (omxresult != OMX_ErrorNone) { | |
| 162 LOG(ERROR) << "SetParameter(OMX_IndexConfigVideoFramerate) failed"; | |
| 163 return false; | |
| 164 } | |
| 165 return true; | |
| 166 } | |
| 167 | |
| 168 } // namespace media | |
| OLD | NEW |