Hi,

Thanks both Dheeraj and Johann. Finally I got it working. I have one
more issue facing now.
When the Surface is created in the Native code, the playback is fine.
But I am trying to simulate the MediaPlayer class where the Surface is
created on the Java side and then they set the surface. using
"mediaPlayer.setDisplay(surfaceHolder);"

My code would look like: Player.java:
Class Player
{
   Surface mSurface;
   private SurfaceView surfaceView;
   private SurfaceHolder surfaceHolder;
   native void play ();

  onCreate ()
  {
        surfaceView = (SurfaceView)
findViewById(R.id.SurfaceViewRendererSurface);
        surfaceHolder = surfaceView.getHolder();
        surfaceHolder.addCallback(this);
        surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
       /* Populate mSurface object here. */
        mSurface = surfaceHolder.getSurface ();
   ......
        play ();
   ......
  }
}

Player.cpp:
.....
.....
struct fields_t {
   jfieldID    surface;
   jfieldID    surface_native;
};
static fields_t fields;

static sp<Surface> get_surface(JNIEnv* env, jobject thiz) {
   Surface* const p = (Surface*)env->GetIntField(thiz,
fields.surface_native);
   return sp<Surface>(p);
}

jint Java_com_test_Media_Media_play (JNIEnv *env, jobject thiz)
{
   sp<Surface> nSurfaceHandle;
   jobject surface = env->GetObjectField(thiz, fields.surface);

   if (surface != NULL) {
      const sp<Surface>& native_surface = get_surface(env, surface);
      nSurfaceHandle = native_surface;

      if (nSurfaceHandle == NULL)
      {
         LOGE ("ERROR :: Surface Handle NULL");
      }
   }
   return 0;
}

static const JNINativeMethod gMethods[] = {
   { "play", "()I", (void*)Java_com_test_Media_Media_play },
};

static int registerMethods(JNIEnv* env) {
   static const char* const kClassName =
      "com/test/Media/Media";
   jclass clazz;

   /* look up the class */
   clazz = env->FindClass(kClassName);
   if (clazz == NULL) {
      LOGE ("Class \"Media\" Not Found");
      return -1;
   }

  /* Access mSurface member object in our Media class */
   fields.surface = env->GetFieldID(clazz, "mSurface", "Landroid/view/
Surface;");
   if (fields.surface == NULL) {
      return -1;
   }

   jclass surface = env->FindClass("android/view/Surface");
   if (surface == NULL) {
      return -1;
   }

   /* Access mSurface member integer in our Surface class */
   fields.surface_native = env->GetFieldID(surface, "mSurface", "I");
   if (fields.surface_native == NULL) {
      return -1;
   }

       return AndroidRuntime::registerNativeMethods(env,
                             kClassName, gMethods, NELEM(gMethods));

}

jint JNI_OnLoad(JavaVM* vm, void* reserved) {
   JNIEnv* env = NULL;
   jint result = -1;

   if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
      LOGI("ERROR: GetEnv failed\n");
      return result;
   }
   assert(env != NULL);

   if (registerMethods(env) != 0) {
      LOGI("ERROR: Media native registration failed\n");
      return result;
   }

   result = JNI_VERSION_1_4;

   return result;
}


In the above code the get_surface is returning NULL i.e., the integer
member from
Surface class is returning 0.

Please let us know what might the cause of this.

Thanks in advance
sandeep

On Feb 5, 8:41 am, dheeraj sharma <dheerajsharm...@gmail.com> wrote:
> Hi sandeep,
>
> Try adding permission for "ACCESS_SURFACE_FLINGER" in your project's
> AndroidManifest.xml.
> and let the changes done in "android.permission.ACCESS_SURFACE_FLINGER" in
> frameworks/base/core/
> res/AndroidManifest.xml to "dangerous" as is,  as it is required.
>
> Cheers,
> Dheeraj
>
> On Wed, Feb 3, 2010 at 10:58 AM, Sandeep Prakash <123sa...@gmail.com> wrote:
> > Hi all,
>
> > I am planning to write a video player application and I am planning to
> > use the gstreamer on the native side. I am trying to use the
> > SurfaceFlinger for the rendering part. For this I have written a test
> > program to experiment on the rendering part. I am using the surface
> > flinger wrapper from the project
>
> >http://gitorious.org/rowboat/external-gst-plugins-android
>
> > But the following ERROR occurs when we try to run the .apk.
>
> > 02-03 09:55:51.258: WARN/ServiceManager(582): Permission failure:
> > android.permission.ACCESS_SURFACE_FLINGER from uid=10032 pid=1361
> > 02-03 09:55:51.258: ERROR/SurfaceFlinger(582): Permission Denial:
> > can't access SurfaceFlinger pid=1361, uid=10032
>
> > The I changed the permission for
> > "android.permission.ACCESS_SURFACE_FLINGER" in frameworks/base/core/
> > res/AndroidManifest.xml to "dangerous" and recompiled. But got the
> > same error.
>
> > Then I commented out the "checkCallingPermission" method in
> > IServiceManager.cpp and recompiled. Then also i got the same error.
>
> > Could someone please suggest any other alternatives or point out if I
> > am going in the wrong track.
>
> > Thanks in advance
> > sandeep
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Developers" group.
> > To post to this group, send email to android-developers@googlegroups.com
> > To unsubscribe from this group, send email to
> > android-developers+unsubscr...@googlegroups.com<android-developers%2bunsubscr...@googlegroups.com>
> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to