您好,欢迎访问三七文档
当前位置:首页 > 行业资料 > 其它行业文档 > Android 蓝牙AVRCP功能的实现
Android蓝牙AVRCP功能的实现作者:MacroLiuAVRCP的按键定义:\sdk\emulator\keymaps\AVRCP.klkey200MEDIA_PLAY_PAUSEWAKEkey201MEDIA_PLAY_PAUSEWAKEkey166MEDIA_STOPWAKEkey163MEDIA_NEXTWAKEkey165MEDIA_PREVIOUSWAKEkey168MEDIA_REWINDWAKEkey208MEDIA_FAST_FORWARDWAKEBCM(broadcom)宏定义需要打开:BOARD_HAVE_BLUETOOTH_BCM:=trueBT音频控制的代码external\bluetooth\bluez\audio\control.c(1)按键的MAPstaticstruct{constchar*name;uint8_tavrcp;uint16_tuinput;}key_map[]={{PLAY,PLAY_OP,KEY_PLAYCD},{STOP,STOP_OP,KEY_STOPCD},{PAUSE,PAUSE_OP,KEY_PAUSECD},{FORWARD,FORWARD_OP,KEY_NEXTSONG},{BACKWARD,BACKWARD_OP,KEY_PREVIOUSSONG},{REWIND,REWIND_OP,KEY_REWIND},{FASTFORWARD,FAST_FORWARD_OP,KEY_FASTFORWARD},{NULL}};(2)按键处理staticvoidhandle_panel_passthrough(structcontrol*control,{…for(i=0;key_map[i].name!=NULL;i++){uint8_tkey_quirks;if((operands[0]&0x7F)!=key_map[i].avrcp)continue;DBG(AVRCP:%s%s,key_map[i].name,status);key_quirks=control-key_quirks[key_map[i].avrcp];if(key_quirks&QUIRK_NO_RELEASE){if(!pressed){DBG(AVRCP:Ignoringrelease);break;}DBG(AVRCP:treatingkeypressaspress+release);send_key(control-uinput,key_map[i].uinput,1);send_key(control-uinput,key_map[i].uinput,0);break;}send_key(control-uinput,key_map[i].uinput,pressed);break;}…}HCIDUMP数据分析以Sony耳机DRC-BT15为例#adbshell#hcidump–X左键:ACLdata:handle12flags0x02dlen12L2CAP(d):cid0x0042len8[psm0]0000:30110e00487c4c000...H|L.HCICommand:ExitSniffMode(0x02|0x0004)plen20000:0c00..ACLdata:handle12flags0x00dlen120000:08004b0032110e09487c4c00..K.2...H|L.HCIEvent:MaxSlotsChange(0x1b)plen30000:0c0005...HCIEvent:ModeChange(0x14)plen60000:000c00000000......HCIEvent:CommandStatus(0x0f)plen40000:0c010408....ACLdata:handle12flags0x02dlen12L2CAP(d):cid0x0042len8[psm0]0000:40110e00487ccc00@...H|?ACLdata:handle12flags0x00dlen120000:08004b0042110e09487ccc00..K.B...H|?HCIEvent:NumberofCompletedPackets(0x13)plen50000:010c000200.....播放/暂停:ACLdata:handle12flags0x02dlen12L2CAP(d):cid0x0042len8[psm0]0000:50110e00487c4b00P...H|K.ACLdata:handle12flags0x00dlen120000:08004b0052110e09487c4b00..K.R...H|K.ACLdata:handle12flags0x02dlen12L2CAP(d):cid0x0042len8[psm0]0000:60110e00487ccb00`...H|?ACLdata:handle12flags0x00dlen120000:08004b0062110e09487ccb00..K.b...H|?HCIEvent:NumberofCompletedPackets(0x13)plen50000:010c000200.....右键:ACLdata:handle12flags0x02dlen12L2CAP(d):cid0x0042len8[psm0]0000:70110e00487c4600p...H|F.ACLdata:handle12flags0x00dlen120000:08004b0072110e09487c4600..K.r...H|F.ACLdata:handle12flags0x02dlen12L2CAP(d):cid0x0042len8[psm0]0000:80110e00487cc600....H|?ACLdata:handle12flags0x00dlen120000:08004b0082110e09487cc600..K.....H|?HCIEvent:NumberofCompletedPackets(0x13)plen50000:010c000200.....HCIEvent:MaxSlotsChange(0x1b)plen30000:0c0001...HCIEvent:ModeChange(0x14)plen60000:000c0002c800....?然后将control.c的日志打印出来:按一次”“播放/暂停键”:D/ACRVP(237):---handle_panel_passthrough----D/ACRVP(237):operands[0]=46对应PAUSE_OPD/ACRVP(237):key_quirks=0,pressed=1按键按下D/ACRVP(237):control-uinput=fffffffe,send_key=201对应MEDIA_PLAY_PAUSED/ACRVP(237):---handle_panel_passthrough----D/ACRVP(237):operands[0]=c6(=0x46|0x80表示按键释放了)D/ACRVP(237):key_quirks=0,pressed=0按键释放D/ACRVP(237):control-uinput=fffffffe,send_key=201对应MEDIA_PLAY_PAUSE再按一次”“播放/暂停键”:D/ACRVP(237):---handle_panel_passthrough----D/ACRVP(237):operands[0]=44对应PLAY_OPD/ACRVP(237):key_quirks=0,pressed=1按键按下D/ACRVP(237):control-uinput=fffffffe,send_key=200对应MEDIA_PLAY_PAUSED/ACRVP(237):---handle_panel_passthrough----D/ACRVP(237):operands[0]=c4D/ACRVP(237):key_quirks=0,pressed=0按键释放D/ACRVP(237):control-uinput=fffffffe,send_key=200对应MEDIA_PLAY_PAUSEnextkey:D/ACRVP(237):---handle_panel_passthrough----D/ACRVP(237):operands[0]=4b对应FORWARD_OPD/ACRVP(237):key_quirks=0,pressed=1D/ACRVP(237):control-uinput=fffffffe,send_key=163对应MEDIA_NEXTD/ACRVP(237):---handle_panel_passthrough----D/ACRVP(237):operands[0]=cbD/ACRVP(237):key_quirks=0,pressed=0D/ACRVP(237):control-uinput=fffffffe,send_key=163prevkey:D/ACRVP(237):---handle_panel_passthrough----D/ACRVP(237):operands[0]=4c对应BACKWARD_OPD/ACRVP(237):key_quirks=0,pressed=1D/ACRVP(237):control-uinput=fffffffe,send_key=165对应D/ACRVP(237):---handle_panel_passthrough----D/ACRVP(237):operands[0]=ccD/ACRVP(237):key_quirks=0,pressed=0D/ACRVP(237):control-uinput=fffffffe,send_key=165MEDIA_PREVIOUS从上面可以看到bluetooth的协议栈blueZ是没有问题的将frameworks\base\libs\ui\EventHub.cpp的LOG打开,只能看到了control.c的日志,EventHub的getEvent完全不响应观察所有log日志发现,openDevice里也没有装载AVRCP.kl初步判断event有问题event分析:$adbshell#cd/proc/bus/input#catdevicescatdevices#catdevicescatdevicesI:Bus=0019Vendor=0001Product=0001Version=0001参考s3c-keypad.cN:Name=s3c-keypadinput_dev-name=DEVICE_NAME;P:Phys=s3c-keypad/input0input_dev-phys=s3c-keypad/input0;S:Sysfs=/devices/virtual/input/input0virtual的?U:Uniq=H:Handlers=event0B:EV=3B:KEY=40004000I:Bus=0019Vendor=0001Product=0001Version=0100参考vpad_buttons.cN:Name=s3c-eintkeyinput-name=pdev-name,gpio_keys_device_driver.name=s3c-eintkey,P:Phys=gpio-keys/input0input-phys=gpio-keys/input0S:Sysfs=/devices/platform/s3c-eintkey/input/input1为什么这里是platform目录?U:Uniq=H:Handlers=event1B:EV=3B:KEY=
本文标题:Android 蓝牙AVRCP功能的实现
链接地址:https://www.777doc.com/doc-23484 .html