| 164 | } |
| 165 | |
| 166 | bool VideoProcessor::processImage(const QImage& img) |
| 167 | { |
| 168 | VideoCodec *codec ; |
| 169 | |
| 170 | switch(_encoding_current_codec) |
| 171 | { |
| 172 | case VIDEO_PROCESSOR_CODEC_ID_JPEG_VIDEO: codec = &_jpeg_video_codec ; |
| 173 | break ; |
| 174 | case VIDEO_PROCESSOR_CODEC_ID_MPEG_VIDEO: codec = &_mpeg_video_codec ; |
| 175 | break ; |
| 176 | default: |
| 177 | codec = NULL ; |
| 178 | } |
| 179 | |
| 180 | // std::cerr << "reducing to " << _frame_size.width() << " x " << _frame_size.height() << std::endl; |
| 181 | |
| 182 | if(codec) |
| 183 | { |
| 184 | RsVOIPDataChunk chunk ; |
| 185 | |
| 186 | if(codec->encodeData(img.scaled(_encoded_frame_size,Qt::IgnoreAspectRatio,Qt::SmoothTransformation),_target_bandwidth_out,chunk) && chunk.size > 0) |
| 187 | { |
| 188 | RS_STACK_MUTEX(vpMtx) ; |
| 189 | _encoded_out_queue.push_back(chunk) ; |
| 190 | _total_encoded_size_out += chunk.size ; |
| 191 | } |
| 192 | |
| 193 | time_t now = time(NULL) ; |
| 194 | |
| 195 | if(now > _last_bw_estimate_out_TS) |
| 196 | { |
| 197 | RS_STACK_MUTEX(vpMtx) ; |
| 198 | |
| 199 | _estimated_bandwidth_out = uint32_t(0.75*_estimated_bandwidth_out + 0.25 * (_total_encoded_size_out / (float)(now - _last_bw_estimate_out_TS))) ; |
| 200 | |
| 201 | _total_encoded_size_out = 0 ; |
| 202 | _last_bw_estimate_out_TS = now ; |
| 203 | |
| 204 | #ifdef DEBUG_VIDEO_OUTPUT_DEVICE |
| 205 | std::cerr << "new bw estimate: " << _estimated_bw << std::endl; |
| 206 | #endif |
| 207 | } |
| 208 | |
| 209 | return true ; |
| 210 | } |
| 211 | else |
| 212 | { |
| 213 | std::cerr << "No codec for codec ID = " << _encoding_current_codec << ". Please call VideoProcessor::setCurrentCodec()" << std::endl; |
| 214 | return false ; |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | bool VideoProcessor::nextEncodedPacket(RsVOIPDataChunk& chunk) |
| 219 | { |