Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scala Wrapper Not Working #24

Open
KhuramKhalid opened this issue Dec 5, 2018 · 7 comments
Open

Scala Wrapper Not Working #24

KhuramKhalid opened this issue Dec 5, 2018 · 7 comments

Comments

@KhuramKhalid
Copy link

Native library throws exception when initialising demux.Movie object with ByteData(arrayOfBytes)

Expected behavior

Should initialise the Movie object without exception.

Actual behavior

Native code throws exception.

Steps to reproduce the behavior

val pathToMP4 = Paths.get("helloworld.mp4")

val bytes = Files.readAllBytes(pathToMP4)

val byteData = new common.ByteData(bytes)

val movie = new demux.Movie(byteData)

If possible, can you provide a Scala example.

hs_err_pid22716.log

@canbal
Copy link
Contributor

canbal commented Dec 5, 2018

Can you try to initialize as follow?

val movie = new demux.Movie("helloworld.mp4")

@KhuramKhalid
Copy link
Author

I tried, it gives syntax error. However, if I try val movie = demux.Movie("helloworld.mp4") then there isn't any syntax error but I get the above mentioned error again.

@canbal
Copy link
Contributor

canbal commented Dec 5, 2018

I think it might be related to the underlying native object being destroyed before the Scala counterpart is gone. Can you try the following? I will try to create a helloworld example for Scala as well.

import resource._

for (movie <- managed(demux.Movie("helloworld.mp4"))) {
  println("video track duration: %d".format(movie.videoTrack.duration())
}

FYI: I didn't have the chance to test this snippet yet. It might be a while before I can provide a well tested sample.

@KhuramKhalid
Copy link
Author

I got the same error with the above code as well. As soon as I access the movie instance within loop, it breaks.

@KhuramKhalid
Copy link
Author

I also tried the following, but still the same error.

object UsingMovie {
  def apply[T](src: String)(f: demux.Movie => T): T = {
    val movie = demux.Movie(src)
    try {
      f(movie)
    } finally {
      movie.close()
    }
  }
}
object App {
  def main(args: Array[String]): Unit = {
    UsingMovie("helloworld.mp4") { movie =>
      println("video track duration: %d".format(movie.videoTrack.duration()))
    }
  }
}

@canbal
Copy link
Contributor

canbal commented Dec 6, 2018 via email

@KhuramKhalid
Copy link
Author

Many thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants