/** * Timer callback used to check about end of media (except JTS type) */ static void CALLBACK audio_timer_callback(UINT uID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2) { audio_handle* pHandle = (audio_handle*)dwUser; if (pHandle->hWnd) { if (-1 == pHandle->duration) { pHandle->duration = MCIWndGetLength(pHandle->hWnd); JAVA_DEBUG_PRINT1("[jc_media] audio_timer_callback %d\n", pHandle->duration); } pHandle->offset = MCIWndGetPosition(pHandle->hWnd); pHandle->curTime = pHandle->offset; /* Is end of media reached? */ if (pHandle->offset >= pHandle->duration) { /* Post EOM event to Java and kill player timer */ pHandle->timerId = 0; pHandle->offset = 0; timeKillEvent(uID); JAVA_DEBUG_PRINT1("[jc_media] javanotify_on_media_notification %d\n", pHandle->playerId); javanotify_on_media_notification(JAVACALL_EVENT_MEDIA_END_OF_MEDIA, pHandle->playerId, (void*)pHandle->duration); } } }
static javacall_result video_start_video_snapshot(javacall_handle handle, const javacall_utf16* imageType, long length) { audio_handle* pHandle = (audio_handle*)handle; char* data; static LimeFunction *f = NULL; if (snapshot_buffer != NULL) { return JAVACALL_FAIL; } if (f == NULL) { f = NewLimeFunction(LIME_MMAPI_PACKAGE, LIME_MMAPI_CLASS, "snapshot"); } f->call(f, &data, &dataLength, pHandle->hWnd, imageType, length); if(data == NULL){ dataLength = -1; } snapshot_buffer = (char *) malloc(dataLength); memcpy(snapshot_buffer, data, dataLength); javanotify_on_media_notification( JAVACALL_EVENT_MEDIA_SNAPSHOT_FINISHED, pHandle->isolateId, pHandle->playerId, NULL == data ? JAVACALL_FAIL : JAVACALL_OK, NULL); return JAVACALL_OK; }
/** * VFW frame grab callback function */ static LRESULT PASCAL camera_grabber_callback(HWND hWnd, LPVIDEOHDR lpVHdr) { #define PNG_HEADER_SIZE (1000) int i; char* pOutput; int copyLineBytes; /* Free previous frame buffer */ if (NULL != _pFrameBuffer) { FREE(_pFrameBuffer); _pFrameBuffer = NULL; } /* Free encoding buffer */ if (NULL != _pEncodingBuffer) { FREE(_pEncodingBuffer); _pEncodingBuffer = NULL; } /* Grab current frame */ if (JAVACALL_TRUE == _grabFrame) { copyLineBytes = (_grabWidth * 3); _pFrameBuffer = MALLOC(lpVHdr->dwBytesUsed); _pEncodingBuffer = MALLOC(javautil_media_get_png_size(_grabWidth, _grabHeight)); if (_pFrameBuffer && _pEncodingBuffer) { pOutput = _pFrameBuffer; /* Impl note: - Top / Bottom Reverse */ for (i = _grabHeight - 1; i >= 0; --i) { memcpy(pOutput, lpVHdr->lpData + (i * copyLineBytes), copyLineBytes); pOutput += copyLineBytes; } _encodingDataSize = javautil_media_rgb_to_png( _pFrameBuffer, _pEncodingBuffer, _grabWidth, _grabHeight); javanotify_on_media_notification(JAVACALL_EVENT_MEDIA_SNAPSHOT_FINISHED, _playerId, 0); } else { if (_pFrameBuffer) { FREE(_pFrameBuffer); _pFrameBuffer = NULL; } if (_pEncodingBuffer) { FREE(_pEncodingBuffer); _pEncodingBuffer = NULL; } } _grabFrame = JAVACALL_FALSE; } InvalidateRect(GET_MCIWND_HWND(), NULL, FALSE); return 0; }
static javacall_result audio_start(javacall_handle handle){ audio_handle* pHandle = (audio_handle*)handle; if (JAVACALL_FALSE == pHandle->isForeground) { JAVA_DEBUG_PRINT("[jc_media] Audio fake start in background!\n"); return JAVACALL_OK; } /* Create MCI window by using temp file */ audio_prepare_MCIWnd(pHandle); JAVA_DEBUG_PRINT1("[jc_media] + javacall_media_start %s\n", pHandle->fileName); /* Seek to play position */ if (pHandle->offset) { MCIWndSeek(pHandle->hWnd, pHandle->offset); pHandle->curTime = pHandle->offset; } else { pHandle->curTime = 0; } /* Start play */ if (pHandle->hWnd && 0 == MCIWndPlay(pHandle->hWnd)) { JAVA_DEBUG_PRINT("[jc_media] - javacall_media_start OK\n"); pHandle->duration = MCIWndGetLength(pHandle->hWnd); javanotify_on_media_notification(JAVACALL_EVENT_MEDIA_DURATION_UPDATED, pHandle->playerId, (void*)pHandle->duration); pHandle->timerId = (UINT)timeSetEvent(TIMER_CALLBACK_DURATION, 100, audio_timer_callback,(DWORD)pHandle, TIME_PERIODIC); return JAVACALL_OK; } return JAVACALL_FAIL; }