2013-03-28 2 views
2

4x 장치에서 비디오를 업로드하는 중 문제가 발생했습니다 .15 초 동안 vedio를 리디렉션하면 삼성 S2에서 30MB 파일이 생성되지만, 웹 서버에 동영상을 업로드하려고하면 D/dalvikvm (7638)과 같은 메시지가 표시됩니다. GC_FOR_ALLOC은 263K, 9 % 무료 12838K/14087K, 일시 중지 13ms, 총 13ms I/dalvikvm-heap (7638) : Grow 1,048,592 바이트 할당 D/dalvikvm (7638)에 대한 14.481MB에 힙 (파편 경우) GC_FOR_ALLOC 총 < 1K/15175K 13861K이 경우 22ms를 일시 무료 9 %, 해방 경우 22ms D/dalvikvm (7638) GC_CONCURRENT는 < 1K 해방 , 9 % 무료 13862K/15175K, 일시 중지 12ms + 2ms, 총 27msdalvikvm-heap grow heap (frag case) 비디오 업로드 중

I know it is the memory managment concept and device memory dependent but I want a real solution for it as I am stuck here from quite a few days. 
Below is my code to call and upload the video to server. 

public void newmethod(String Imageurl) throws ClientProtocolException, IOException 
{ 
    byte[] data ; 
    int bytenumber,bufferSize,bytesRead; 
    int maxBufferSize = 1*1024*1024; 
     DataOutputStream dos = null; 
    //File sourceFile = searchForFileInExternalStorage("video.3gp"); 

    Log.e("in the method the path", ""+Imageurl); 

     FileInputStream fileInputStream = new FileInputStream(Imageurl); 
     bytenumber = fileInputStream.available(); 
     Log.e("in the method the the size of the file is", ""+bytenumber); 
    // dos = new DataOutputStream(conn.getOutputStream()); 
     bufferSize = Math.min(bytenumber, maxBufferSize); 
     data = new byte[bufferSize]; 
    //ProgressDialog pr = new ProgressDialog(getApplicationContext()); 
    // pr.addContentView(getCurrentFocus(), null); 
     // read file and write it into form... 
     bytesRead = fileInputStream.read(data, 0, bufferSize); 

     while (bytesRead > 0) { 
     // dos.write(data, 0, bufferSize); 
     bytenumber = fileInputStream.available(); 
     bufferSize = Math.min(bytenumber, maxBufferSize); 
     bytesRead = fileInputStream.read(data, 0, bufferSize); 
     } 

    // pr.show(); 


    HttpClient httpClient = new DefaultHttpClient(); 
    HttpPost postRequest = new HttpPost("http://67.52.165.116/Kakz/mobiles/uploadvideo"); 
    ByteArrayBody bab = new ByteArrayBody(data, Imageurl); 
    MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); 
    reqEntity.addPart("user_video", bab); 

    FormBodyPart bodyPart=new FormBodyPart("title", new StringBody(title)); 
    reqEntity.addPart(bodyPart); 
    bodyPart=new FormBodyPart("desc", new StringBody(description)); 
    reqEntity.addPart(bodyPart); 
    bodyPart=new FormBodyPart("source", new StringBody("android")); 
    reqEntity.addPart(bodyPart); 
    postRequest.setEntity(reqEntity); 
    final HttpResponse response = httpClient.execute(postRequest); 
    // FileInputStream fileInputStream = new FileInputStream(response.getEntity().getContent()); 


    runOnUiThread(new Runnable() { 
     public void run() { 

    //stuff that updates ui 

      BufferedReader in = null; 
      try { 
       in = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); 

      } catch (IllegalStateException e1) { 
       // TODO Auto-generated catch block 
       e1.printStackTrace(); 
      } catch (IOException e1) { 
       // TODO Auto-generated catch block 
       e1.printStackTrace(); 
      } 
       String line = null; 

    try { 
     while((line = in.readLine()) != null) { 
      System.out.println(line); 

      titleText.setText(""); 
      descriptionText.setText(""); 
      // Toast.makeText(getApplicationContext(), "Video Uploaded successfully", Toast.LENGTH_LONG).show(); 

      if (line.equalsIgnoreCase("Its too Heavy")) { 
      // pr.dismiss(); 
       // titleText.setText(""); 
       //descriptionText.setText(""); 
       Toast.makeText(getApplicationContext(), "Video size is too heavy", Toast.LENGTH_LONG).show(); 

      } 

      else if (line.equalsIgnoreCase("Error")) { 
      // pr.dismiss(); 
       // titleText.setText(""); 
       //descriptionText.setText(""); 
       Toast.makeText(getApplicationContext(), "Error uploading video", Toast.LENGTH_LONG).show(); 


      } 

      else if (line.equalsIgnoreCase("Uploaded")) { 
       //pr.dismiss(); 
       //titleText.setText(""); 
       //descriptionText.setText(""); 
       Toast.makeText(getApplicationContext(), "Video uploaded successfully", Toast.LENGTH_LONG).show(); 

      } 

     } 
    } catch (IOException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 
     } 
}); 

Please let me know that how I should manage the code to get it right. 
Any help would be appreciated ASAP`enter code here` 
+0

백그라운드 스레드에 업로드 ?? – Raghunandan

+0

꽤 오랫동안 스팸 메일을받지 못하면 걱정하지 않을 것입니다. 당신은 무거운 행동을하고 있으며 단지 약간의 기억이 필요합니다. 앱은 시작부터 최소 힙 크기를 가지며 이러한 경우 증가 할 여지가 있습니다. –

+0

@Raghunandan 예. asyntask 배경에 업로드하고 있습니다. – vyas

답변

1

4x 장치에서 비디오를 업로드 할 때 문제가 발생합니다.

문제가되지 않습니다. 매우 높은 비용의 작업을 수행 할 때 정상적인 동작입니다. 귀하의 힙 크기 (암시 적으로 결정)는 한 순간에 충분하지 않아서 자랄 필요가 있습니다. 그것은 당신이 매니 페스트에 써야하는 것과 동등한 행동입니다.

android:largeHeap="true" 

이 속성은 작동하지 않습니다. 힙이 더 많은 크기를 필요로 할 때 필요할 때마다 자랄 것입니다. 이 메시지는 대개 메모리가 충분하지 않을 때 표시됩니다.

GC_FOR_ALLOC은 263K, 당신은 단지 9 % 메모리와 힙이 성장 할 필요가있다 여기에 (7638)

/14087K 12838K가,을 13ms 일시 중지 무료 9 %, 총 을 13ms I/dalvikvm 힙을 해제 . 일반적으로 ALLOC이 10 % 미만일 때 발생하며 스레드로 작업하는 경우 중요하지 않습니다. 한 번 높은 비용으로 작업합니다. 또한 힙 크기가 하나의 "임계점"에 도달하면 응용 프로그램이 VM뿐 아니라 보안상의 이유로 자동으로 중지됩니다.

하나의 가능한 솔루션은 파일을 더 작은 청크로 분할하고 하나씩 업로드해야한다는 것입니다.

+0

설명을위한 Thnx 이미 여러 부분으로 된 비디오를 보내고 있습니다. 거기에 비디오를 여러 조각으로 나눌 필요가있는 것이 있습니까? – vyas

+0

@vyas 서버에 보낼 때 파일을 프로그램 적으로 작은 덩어리로 나눌 수는 있지만 서버에서는 병합해야하지만 지금은이 아이디어가 비디오 이후로 좋지 않습니다. 나는 그 큰 파일 이래로 그것을 어떻게 의미 했는가, 그것을 고치는 것이 아니다. logcat에서 유일한 경고이며 파일이 성공적으로 업로드되면 CPU 및 RAM에 문제가 없습니다. – Sajmon

0

나는 내 자신의 질문에 대답하는 것이 좋은 생각인지 모른다. 하지만 여전히 나 같은 같은 문제에 직면 해있는 사람들을 위해 내 경험을 쏟아 붓는 느낌이 듭니다. 물건을 많이 찾은 후에는 장치 의존적이고 많은 메모리 사용 과정 때문에이 문제에 대한 특별한 해결책이 없다는 것을 알아야하기 때문입니다. 그런 다음 업로드하기 전에 비디오를 압축하는 것과 같은 다른 옵션을 찾았지만 이에 대한 오픈 소스 라이브러리도 없었습니다. 그래서 지금은 비디오 업로드가 제가 생각했던 것처럼 간단하지 않습니다. :)