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

camera support #176

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

camera support #176

wants to merge 2 commits into from

Conversation

wiomoc
Copy link

@wiomoc wiomoc commented Jan 17, 2020

No description provided.

@jlusiardi
Copy link
Owner

jlusiardi commented Jan 18, 2020

hey, nice work!

I can perform a pairing with my iPhone using this demoserver.json

{
  "accessory_ltpk": "8bbaf1ee0e9b6669535c19355cc2e9eeec448a04c105c891dd851e88cb8674c8",
  "accessory_ltsk": "5a15ed1673db599a3224f565829f341f5a8564051149c1e1a9cd59f6fade80a3",
  "accessory_pairing_id": "12:00:00:00:01:0F",
  "accessory_pin": "031-45-154",
  "c#": 12,
  "category": "IP Camera",
  "host_ip": "192.168.178.XXX",
  "host_port": 51841,
  "name": "Camera",
  "peers": {
    "9C0C94F4-6A93-4067-993D-CBEE2D6E4006": {
      "admin": true,
      "key": "fb491bb43ca3240fac077b3c7f1055a7912451983a092bb0d2c26d263d8a51fa"
    }
  },
  "unsuccessful_tries": 0
}

but it never tries to start the ffmpeg part (which will fail anyway because i will have to adjust at leas the cam device).

@wiomoc
Copy link
Author

wiomoc commented Jan 28, 2020

Good question, because the specs are also stating in table 14-2:

Little endian integer. This must use the minimum number of bytes to encode the integer.

@jlusiardi
Copy link
Owner

Good point, can we check what an iOS device is sending/expecting? As stated at least one 'real' accessory uses 2 bytes here.

@wiomoc
Copy link
Author

wiomoc commented Jan 28, 2020

The Apple Homekit Accessory Simulator has following value for supported-audio-configuration,
the codec types are one byte long

00000000: 0111 0101 *00*02 0c01 0101 0201 0002 0101  ................
00000010: 0301 0001 1101 *01*01 020c 0101 0102 0100  ................  
00000020: 0201 0103 0100 0111 0101 *02*02 0c01 0101  ................
00000030: 0201 0003 0101 0301 0201 1701 01*03* 0212  ................
00000040: 0101 0102 0100 0201 0103 0100 0301 0103  ................
00000050: 0102 0201 00                             .....`

Strange is the fact that codec types 0 and 1 do not appear in the specification

@Jc2k
Copy link
Collaborator

Jc2k commented Jan 28, 2020

Theres some relevant discussion that might be useful here.

There are some additional codecs that were found in the homekit binaries but not in the spec, as you noticed with the simulator:

  case 0:
    pcVar2 = &cf_HMDAudioCodecGroupTypePCMU;
    break;
  case 1:
    pcVar2 = &cf_HMDAudioCodecGroupTypePCMA;
    break;
  case 2:
    pcVar2 = &cf_HMDAudioCodecGroupTypeAACELD;
    break;
  case 3:
    pcVar2 = &cf_HMDAudioCodecGroupTypeOpus;
    break;
  case 4:
    pcVar2 = &cf_HMDAudioCodecGroupTypeMSBC;
    break;
  case 5:
    pcVar2 = &cf_HMDAudioCodecGroupTypeAMR;
    break;
  case 6:
    pcVar2 = &cf_HMDAudioCodecGroupTypeAMRWB;
    break;

Theres also some discussion around how e.g. opus is problematic.

Someone has also figured out how to make secure video work here.

@jlusiardi
Copy link
Owner

@wiomoc I started merging your branch under wiomoc_camera and an own branch camera. There I will add some commands to work with your democamserver and the circle2 camera. This ffmpeg stuff is pretty complicated for figuring out the parameters 😅

@jlusiardi
Copy link
Owner

@wiomoc i am not fully sure if i understand TLVItem properly and how it encodes lists of elements.

Take 9.105 Supported Video Stream Configuration for example. We can have multiple instances of Video Attributes to offer multiple resolutions and frame rates.

The code from the democameraserver returns the following data for 2 entries:

[[3, bytearray(b'\x01\x02\x80\x07\x02\x028\x04\x03\x01\x1e\x01\x02@\x01\x02\x01\xf0\x03\x01\x0f')]]

But the Circle2 camera returns:

[[3, bytearray(b'\x01\x02\x00\x05\x02\x02\xd0\x02\x03\x01\x1e')], [255, bytearray(b'')], [3, bytearray(b'\x01\x02\x80\x02\x02\x02h\x01\x03\x01\x1e')]]

I think this is consistent with "An IP camera accessory supporting encoding video at different resolutions must include multiple instances of Video attributes TLV." (page 221 / Spec Revision 2) and "There may be multiple, separate TLV items of the same type if separated by a TLV item of a different type." (page 254 / Spec Revision 2). Page 51 / Table 5-6 lists kTLVType_Separator = 0xff with a length of 0 as separator. Is this possible to achieve with your code?

@jlusiardi
Copy link
Owner

Hey @wiomoc,

i tried to pull out the whole TLV generation to a module of itself: https://github.com/jlusiardi/tlv8_python

This might simplify using TLV8 and I think I can code some examples how to use it in the camera area of the code.

Can you please have a look on the module?

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

Successfully merging this pull request may close these issues.

3 participants