1/* 2 * Copyright 2011 castLabs, Berlin 3 * 4 * Licensed under the Apache License, Version 2.0 (the License); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an AS IS BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.googlecode.mp4parser.boxes.mp4; 18 19import com.googlecode.mp4parser.AbstractFullBox; 20import com.googlecode.mp4parser.boxes.mp4.objectdescriptors.BaseDescriptor; 21import com.googlecode.mp4parser.boxes.mp4.objectdescriptors.ObjectDescriptorFactory; 22 23import java.io.IOException; 24import java.nio.ByteBuffer; 25import java.util.logging.Level; 26import java.util.logging.Logger; 27 28/** 29 * ES Descriptor Box. 30 */ 31public class AbstractDescriptorBox extends AbstractFullBox { 32 private static Logger log = Logger.getLogger(AbstractDescriptorBox.class.getName()); 33 34 35 public BaseDescriptor descriptor; 36 public ByteBuffer data; 37 38 public AbstractDescriptorBox(String type) { 39 super(type); 40 } 41 42 @Override 43 protected void getContent(ByteBuffer byteBuffer) { 44 writeVersionAndFlags(byteBuffer); 45 data.rewind(); // has been fforwarded by parsing 46 byteBuffer.put(data); 47 } 48 49 @Override 50 protected long getContentSize() { 51 return 4 + data.limit(); 52 } 53 54 public BaseDescriptor getDescriptor() { 55 return descriptor; 56 } 57 58 public String getDescriptorAsString() { 59 return descriptor.toString(); 60 } 61 62 public void setData(ByteBuffer data) { 63 this.data = data; 64 } 65 66 @Override 67 public void _parseDetails(ByteBuffer content) { 68 parseVersionAndFlags(content); 69 data = content.slice(); 70 content.position(content.position() + content.remaining()); 71 try { 72 data.rewind(); 73 descriptor = ObjectDescriptorFactory.createFrom(-1, data); 74 } catch (IOException e) { 75 log.log(Level.WARNING, "Error parsing ObjectDescriptor", e); 76 //that's why we copied it ;) 77 } catch (IndexOutOfBoundsException e) { 78 log.log(Level.WARNING, "Error parsing ObjectDescriptor", e); 79 //that's why we copied it ;) 80 } 81 82 } 83 84} 85