{"action":"created","issue":{"url":"https://api.github.com/repos/begeekmyfriend/yasea/issues/629","repository_url":"https://api.github.com/repos/begeekmyfriend/yasea","labels_url":"https://api.github.com/repos/begeekmyfriend/yasea/issues/629/labels{/name}","comments_url":"https://api.github.com/repos/begeekmyfriend/yasea/issues/629/comments","events_url":"https://api.github.com/repos/begeekmyfriend/yasea/issues/629/events","html_url":"https://github.com/begeekmyfriend/yasea/issues/629","id":332632417,"node_id":"MDU6SXNzdWUzMzI2MzI0MTc=","number":629,"title":"ByteArray.allocateDirect 创建的ByteArray，使用array() 获取的数据有问题","user":{"login":"ZengHK2018","id":11402747,"node_id":"MDQ6VXNlcjExNDAyNzQ3","avatar_url":"https://avatars0.githubusercontent.com/u/11402747?v=4","gravatar_id":"","url":"https://api.github.com/users/ZengHK2018","html_url":"https://github.com/ZengHK2018","followers_url":"https://api.github.com/users/ZengHK2018/followers","following_url":"https://api.github.com/users/ZengHK2018/following{/other_user}","gists_url":"https://api.github.com/users/ZengHK2018/gists{/gist_id}","starred_url":"https://api.github.com/users/ZengHK2018/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ZengHK2018/subscriptions","organizations_url":"https://api.github.com/users/ZengHK2018/orgs","repos_url":"https://api.github.com/users/ZengHK2018/repos","events_url":"https://api.github.com/users/ZengHK2018/events{/privacy}","received_events_url":"https://api.github.com/users/ZengHK2018/received_events","type":"User","site_admin":false},"labels":[{"id":353621162,"node_id":"MDU6TGFiZWwzNTM2MjExNjI=","url":"https://api.github.com/repos/begeekmyfriend/yasea/labels/bug","name":"bug","color":"ee0701","default":true}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2018-06-15T03:09:27Z","updated_at":"2018-06-15T08:41:55Z","closed_at":"2018-06-15T08:33:43Z","author_association":"NONE","body":"问题详情: https://github.com/begeekmyfriend/yasea/issues/415\r\n因为我的小米5S 手机也在推流后观看出现左边有一条线。其他手机也出现过。\r\n\r\n经过几天深入的研究终于发现并解决此Bug.\r\n见: https://blog.csdn.net/ilittleone/article/details/46659183\r\n**因allocateDirect 申请的内存有对齐问题，不能直接用 array() 作为数据传递.**\r\n\r\n测试过程:\r\n`\r\n       \r\n        int[] intArray = {1};\r\n        IntBuffer intBuffer = IntBuffer.allocate(1);\r\n        intBuffer.put(intArray);\r\n        Log.i(TAG, \"capacity:\" + intBuffer.capacity() + \" \" + Arrays.toString(intBuffer.array()));\r\n        //输出  capacity:1 [1]\r\n\r\n        ByteBuffer byteBuffer = ByteBuffer.allocate(4);\r\n        byteBuffer.asIntBuffer().put(intBuffer.array());\r\n        Log.i(TAG, \"capacity:\" + byteBuffer.capacity() + \" \" + Arrays.toString(byteBuffer.array()));\r\n        //输出  capacity:4 [0, 0, 0, 1]\r\n        //正确结果.\r\n\r\n        ByteBuffer byteDirectBuffer = ByteBuffer.allocateDirect(4);\r\n        byteDirectBuffer.asIntBuffer().put(intBuffer.array());\r\n        Log.i(TAG, \"capacity:\" + byteDirectBuffer.capacity() + \" \" + Arrays.toString(byteDirectBuffer.array()));\r\n        //输出  capacity:4 [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0]\r\n        //错误结果.  因为allocateDirect 申请的内存空间有字节对齐，会有额外的数据.\r\n`\r\n问题定位:\r\nhttps://github.com/begeekmyfriend/yasea/blob/master/library/src/main/java/net/ossrs/yasea/SrsCameraView.java#L158\r\n\r\n2种解决方式:\r\n        1. allocateDirect() 改用 allocate()\r\n        2. `\r\n\r\n           byte[] output = new byte[byteDirectBuffer.capacity()];\r\n           byteDirectBuffer.get(output);`\r\n           使用output 替代 byteDirectBuffer.array()\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/begeekmyfriend/yasea/issues/comments/397554597","html_url":"https://github.com/begeekmyfriend/yasea/issues/629#issuecomment-397554597","issue_url":"https://api.github.com/repos/begeekmyfriend/yasea/issues/629","id":397554597,"node_id":"MDEyOklzc3VlQ29tbWVudDM5NzU1NDU5Nw==","user":{"login":"begeekmyfriend","id":6031938,"node_id":"MDQ6VXNlcjYwMzE5Mzg=","avatar_url":"https://avatars3.githubusercontent.com/u/6031938?v=4","gravatar_id":"","url":"https://api.github.com/users/begeekmyfriend","html_url":"https://github.com/begeekmyfriend","followers_url":"https://api.github.com/users/begeekmyfriend/followers","following_url":"https://api.github.com/users/begeekmyfriend/following{/other_user}","gists_url":"https://api.github.com/users/begeekmyfriend/gists{/gist_id}","starred_url":"https://api.github.com/users/begeekmyfriend/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/begeekmyfriend/subscriptions","organizations_url":"https://api.github.com/users/begeekmyfriend/orgs","repos_url":"https://api.github.com/users/begeekmyfriend/repos","events_url":"https://api.github.com/users/begeekmyfriend/events{/privacy}","received_events_url":"https://api.github.com/users/begeekmyfriend/received_events","type":"User","site_admin":false},"created_at":"2018-06-15T08:41:55Z","updated_at":"2018-06-15T08:41:55Z","author_association":"OWNER","body":"我试过`byteDirectBuffer.get`还是不行，恐怕这个方法跟`array`方法一样"}}
{"actor":{"display_login":"begeekmyfriend"}}