C/c++&java communicate with the video file-streaming

Source: Internet
Author: User

Use open source Communication framework AllJoyn to do equipment, service search, Discovery, communication, detailed principle reference https://allseenalliance.org/developers/learn/core/system-description/ Advertisement-discovery GStreamer for media playback.                                                             Interested students can look at the Https://github.com/europelee/AjUtil, simple multimedia file stream sharing (that is, its architecture) (AllJoyn equipment, service announcements, discovery) involves:1. Multiple native threads in JNI and Java Communication processing:jnienv, JAVA_VM, thread:jnienv cannot be co-owned by multiple native threads, that is, jnienv is unique to each thread, it is thread-related, then
for a native thread, if you need to use jnienv, you need to get it owned by JAVAVM's Attachcurrentthread method.  For example, the following set_ui_message, when the internal native thread is running, needs to notify some messages to the Java layer of Android, get_jni_env to get its own jnienv. 2.thread-specific Datadid you notice current_jni_env? If Set_ui_message is called within multiple native threads, what is pthread_getspecific in the Get_jni_env function ? current_jni_env A global variable to ensure that the Env pointer is unique for each thread ?  Normally , a global variable is shared for multiple threads within a process, but if the thread wants to own it separately, the POSIX-supplied thread-specific Data can be used, i.e. Thread-private data, so it looks like this is a global variable that all threads can use, but its value is stored separately in each thread , a thread- related data structure that uses the same name and different variable addresses. Using the Pthread_key_create function to create pthread_key_create (&current_jni_env, detach_current_thread);  

3. Code:

/* Register This thread with the VM */static jnienv *Attach_current_thread(void) {jnienv *env;  Javavmattachargs args; Gst_debug ("Attaching Thread%p", g_thread_self ()); Args.version = jni_version_1_4; Args.name = NULL;  Args.group = NULL; if ((*JAVA_VM)->attachcurrentthread (JAVA_VM, &env, &args) < 0) {Gst_error ("Failed to attach current thread  "); return NULL; } return env;} /* Retrieve The JNI environment for this thread */static jnienv *get_jni_env(void)  {jnienv *env; if (env = pthread_getspecific (current_jni_env) = = NULL) {env =Attach_current_thread(); Pthread_setspecific (current_jni_env, env); } return env;} /* Change the content of the UI ' s TextView */static voidSet_ui_message(const Gchar *message, CustomData *data) {jnienv *env = get_jni_env ();Gst_debug ("Setting Message to:%s", message); Jstring jmessage = (*env)->newstringutf (env, message); (*env)->callvoidmethod (env, Data->app, set_message_method_id, jmessage);  if ((*env)->exceptioncheck (env)) {Gst_error ("Failed to call Java method"); (*env)->exceptionclear (env); } (*ENV)->deletelocalref (env, jmessage);}

C/c++&java communicate with the video file-streaming

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.