1 /* 2 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 #ifndef _JAVA_PLAYER_EVENT_DISPATCHER_H_ 27 #define _JAVA_PLAYER_EVENT_DISPATCHER_H_ 28 29 #include <jni.h> 30 31 #include <PipelineManagement/AudioTrack.h> 32 #include <PipelineManagement/VideoTrack.h> 33 #include <PipelineManagement/SubtitleTrack.h> 34 #include <PipelineManagement/PlayerEventDispatcher.h> 35 #include <PipelineManagement/Pipeline.h> 36 #include <PipelineManagement/VideoFrame.h> 37 #include <MediaManagement/Media.h> 38 #include <MediaManagement/MediaWarningListener.h> 39 40 using namespace std; 41 42 class CJavaPlayerEventDispatcher : public CPlayerEventDispatcher 43 { 44 public: 45 CJavaPlayerEventDispatcher(); 46 ~CJavaPlayerEventDispatcher(); 47 48 void Init(JNIEnv *env, jobject PlayerInstance, CMedia* pMedia); 49 void Dispose(); 50 51 virtual bool SendPlayerMediaErrorEvent(int errorCode); 52 virtual bool SendPlayerHaltEvent(const char* message, double mstTime); 53 virtual bool SendPlayerStateEvent(int newState, double presentTime); 54 virtual bool SendNewFrameEvent(CVideoFrame* pVideoFrame); 55 virtual bool SendFrameSizeChangedEvent(int width, int height); 56 virtual bool SendAudioTrackEvent(CAudioTrack* pTrack); 57 virtual bool SendVideoTrackEvent(CVideoTrack* pTrack); 58 virtual bool SendSubtitleTrackEvent(CSubtitleTrack* pTrack); 59 virtual bool SendMarkerEvent(string name, double time); 60 virtual bool SendBufferProgressEvent(double clipDuration, int64_t start, int64_t stop, int64_t position); 61 virtual bool SendDurationUpdateEvent(double time); 62 virtual bool SendAudioSpectrumEvent(double time, double duration); 63 virtual void Warning(int warningCode, const char* warningMessage); 64 65 private: 66 JavaVM *m_PlayerVM; 67 jobject m_PlayerInstance; 68 jlong m_MediaReference; // FIXME: Nuke this field, it's completely unused 69 70 static jmethodID m_SendWarningMethod; 71 72 static jmethodID m_SendPlayerMediaErrorEventMethod; 73 static jmethodID m_SendPlayerHaltEventMethod; 74 static jmethodID m_SendPlayerStateEventMethod; 75 static jmethodID m_SendNewFrameEventMethod; 76 static jmethodID m_SendFrameSizeChangedEventMethod; 77 static jmethodID m_SendAudioTrackEventMethod; 78 static jmethodID m_SendVideoTrackEventMethod; 79 static jmethodID m_SendSubtitleTrackEventMethod; 80 static jmethodID m_SendMarkerEventMethod; 81 static jmethodID m_SendBufferProgressEventMethod; 82 static jmethodID m_SendDurationUpdateEventMethod; 83 static jmethodID m_SendAudioSpectrumEventMethod; 84 85 bool SendToJava_PlayerMediaErrorEvent(int errorCode); 86 bool SendToJava_PlayerHaltEvent(const char* message, double time); 87 bool SendToJava_PlayerStateEvent(long newJavaState, double presentTime); 88 bool SendToJava_NewFrameEvent(CVideoFrame* pVideoFrame); 89 bool SendToJava_FrameSizeChangedEvent(int width, int height); 90 bool SendToJava_AudioTrackEvent(CAudioTrack* pTrack); 91 bool SendToJava_VideoTrackEvent(CVideoTrack* pTrack); 92 bool SendToJava_SubtitleTrackEvent(CSubtitleTrack* pTrack); 93 bool SendToJava_MarkerEvent(string name, double time); 94 bool SendToJava_BufferProgressEvent(double clipDuration, int64_t start, int64_t stop, int64_t position); 95 bool SendToJava_StopReachedEvent(double time); 96 bool SendToJava_DurationUpdateEvent(double time); 97 bool SendToJava_AudioSpectrumEvent(double time, double duration); 98 99 static jobject CreateObject(JNIEnv *env, jmethodID *cid, 100 const char* class_name, const char* signature, 101 jvalue* value); 102 static jobject CreateBoolean(JNIEnv *env, jboolean boolean_value); 103 static jobject CreateInteger(JNIEnv *env, jint int_value); 104 static jobject CreateLong(JNIEnv *env, jlong long_value); 105 static jobject CreateDouble(JNIEnv *env, jdouble double_value); 106 static jobject CreateDuration(JNIEnv *env, jlong duration); 107 }; 108 109 #endif // _JAVA_PLAYER_EVENT_DISPATCHER_H_