MCPcopy Create free account
hub / github.com/defold/defold / New

Function New

engine/record/src/record/record.cpp:114–185  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

112 }
113
114 Result New(const NewParams* params, HRecorder* recorder)
115 {
116 *recorder = 0;
117
118 if (params->m_ContainerFormat != CONTAINER_FORMAT_IVF)
119 {
120 return RESULT_INVAL_ERROR;
121 }
122
123 if (params->m_VideoCodec != VIDOE_CODEC_VP8)
124 {
125 return RESULT_INVAL_ERROR;
126 }
127
128 if (params->m_Filename == 0)
129 {
130 return RESULT_INVAL_ERROR;
131 }
132 else if (params->m_Width % 8 != 0 || params->m_Height % 8 != 0
133 || params->m_Width == 0 || params->m_Height == 0)
134 {
135 dmLogError("Window width and height must be a multiple of 8. Current width: %d; height: %d", params->m_Width, params->m_Height);
136 return RESULT_INVAL_ERROR;
137 }
138
139 vpx_codec_enc_cfg_t cfg;
140 vpx_image_t vpx_image;
141 if(!vpx_img_alloc(&vpx_image, VPX_IMG_FMT_YV12, params->m_Width, params->m_Height, 1))
142 {
143 return RESULT_UNKNOWN_ERROR;
144 }
145
146 vpx_codec_err_t res = vpx_codec_enc_config_default(vpx_codec_vp8_cx(), &cfg, 0);
147 if (res)
148 {
149 dmLogError("Failed to get default configuration (%s)", vpx_codec_err_to_string(res));
150 vpx_img_free(&vpx_image);
151 return RESULT_UNKNOWN_ERROR;
152 }
153
154 cfg.rc_target_bitrate = params->m_Width * params->m_Height * cfg.rc_target_bitrate / cfg.g_w / cfg.g_h;
155 cfg.g_w = params->m_Width;
156 cfg.g_h = params->m_Height;
157 cfg.g_timebase.num = 1;
158 cfg.g_timebase.den = params->m_Fps;
159
160 vpx_codec_ctx_t codec;
161 res = vpx_codec_enc_init(&codec, vpx_codec_vp8_cx(), &cfg, 0);
162 if(res)
163 {
164 dmLogError("Unable to init codec (%s)", vpx_codec_err_to_string(res));
165 vpx_img_free(&vpx_image);
166 return RESULT_UNKNOWN_ERROR;
167 }
168
169 FILE* f = fopen(params->m_Filename, "wb");
170 if (!f)
171 {

Callers 7

TESTFunction · 0.50
CreateFunction · 0.50
NewFactoryFunction · 0.50
MountFunction · 0.50
CreateQueueFunction · 0.50
TESTFunction · 0.50
NewFontMapFunction · 0.50

Calls

no outgoing calls

Tested by 2

TESTFunction · 0.40
TESTFunction · 0.40